add google.py

This commit is contained in:
Jaewook Lee
2024-09-04 13:41:58 +00:00
parent fbb3d7fcb9
commit 33c61a6676

View File

@@ -1,3 +1,26 @@
```python
# google.py
#%%
import xvfbwrapper, playwright.async_api
from PIL import Image; from io import *
#%%
xvfbwrapper.Xvfb().start()
playwright = await playwright.async_api.async_playwright().start()
browser = await playwright.chromium.launch(headless=False,
args=['--enable-features=WebContentsForceDark'])
page = await browser.new_page()
#%%
await page.goto('https://google.com')
image = Image.open(BytesIO(await page.screenshot()))
image.save('google.png')
```
위의 `google.py`는 top-level await를 사용하므로 아래와 같이 실행해야 한다.
```sh
python -m asyncio < google.py
```
```python
# play.py
from playwright.async_api import async_playwright as aP