Files
wiki/playwright/README.md
2024-11-19 08:10:33 -05:00

836 B

"""
WSL Debian

pip install playwright nest_asyncio
playwright install --with-deps
"""
# %%
import asyncio, nest_asyncio, functools; nest_asyncio.apply()
@(sync := lambda coro: 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))
    page.goto = lambda url, goto=page.goto: goto(url) and Image(page.screenshot())
    return page
(page := Page()).goto('https://naver.com')
print(page.title()) # NAVER