24 lines
839 B
Markdown
24 lines
839 B
Markdown
```python
|
|
"""
|
|
WSL Debian
|
|
|
|
pip install playwright nest_asyncio
|
|
playwright install --with-deps
|
|
"""
|
|
# %%
|
|
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
|
|
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')
|
|
print(page.title()) # NAVER
|
|
``` |