API Playwright Sync внутри цикла asyncioPython

Программы на Python
Anonymous
API Playwright Sync внутри цикла asyncio

Сообщение Anonymous »

Итак, я впервые работаю с драматургом, поэтому решил попробовать примеры, но ничего не нашел, а ошибки не имеют смысла:
Я перепробовал все примеры в документации и на страницах GitHub и продолжаю получать ошибки, которые я просто не понимаю.
КОД:
`

from playwright.sync_api import sync_playwright

playwright = sync_playwright().start()

browser = playwright.chromium.launch()
page = browser.new_page()
page.goto("https://playwright.dev/")
page.screenshot(path="example.png")
browser.close()

playwright.stop()

`
**ОШИБКА:
**
---------------------------------------------------------------------------
Error Traceback (most recent call last)
Cell In[23], line 3
1 from playwright.sync_api import sync_playwright
----> 3 playwright = sync_playwright().start()
5 browser = playwright.chromium.launch()
6 page = browser.new_page()

File ~/Downloads/Packaging Industry Anomaly DEtection (PIADE)/venv/lib/python3.12/site-packages/playwright/sync_api/_context_manager.py:84, in PlaywrightContextManager.start(self)
83 def start(self) -> SyncPlaywright:
---> 84 return self.__enter__()

File ~/Downloads/Packaging Industry Anomaly DEtection (PIADE)/venv/lib/python3.12/site-packages/playwright/sync_api/_context_manager.py:47, in PlaywrightContextManager.__enter__(self)
45 self._own_loop = True
46 if self._loop.is_running():
---> 47 raise Error(
48 """It looks like you are using Playwright Sync API inside the asyncio loop.
49 Please use the Async API instead."""
50 )
52 # Create a new fiber for the protocol dispatcher. It will be pumping events
53 # until the end of times. We will pass control to that fiber every time we
54 # block while waiting for a response.
55 def greenlet_main() -> None:

Error: It looks like you are using Playwright Sync API inside the asyncio loop.
Please use the Async API instead.


Подробнее здесь: https://stackoverflow.com/questions/787 ... yncio-loop

Вернуться в «Python»