Update playwright/README.md
This commit is contained in:
@@ -6,17 +6,17 @@ pip install playwright nest_asyncio
|
||||
playwright install --with-deps
|
||||
"""
|
||||
# %%
|
||||
import asyncio, nest_asyncio, functools; nest_asyncio.apply()
|
||||
@(sync := lambda coro: functools.wraps(coro)(
|
||||
import asyncio; __import__('nest_asyncio').apply()
|
||||
@(sync := lambda coro: __import__('functools').wraps(coro)(
|
||||
lambda *args, **kwargs: asyncio.run(coro(*args, **kwargs))))
|
||||
async def Page():
|
||||
from playwright.async_api import async_playwright
|
||||
from IPython.display import Image
|
||||
browser = await (await async_playwright().start()).firefox.launch()
|
||||
(page := await browser.new_page()).set_default_timeout(0)
|
||||
for attr in dir(page):
|
||||
if asyncio.iscoroutinefunction(method := getattr(page, attr)):
|
||||
setattr(page, attr, sync(method))
|
||||
from IPython.display import Image
|
||||
page.goto = lambda url, goto=page.goto: goto(url) and Image(page.screenshot())
|
||||
return page
|
||||
(page := Page()).goto('https://naver.com')
|
||||
|
||||
Reference in New Issue
Block a user