python playwright怎么连接已开启的浏览器
时间: 2024-05-03 19:20:25 浏览: 194
python-playwright-01
Python Playwright可以使用`connect`方法连接已经打开的浏览器。代码示例:
```python
from playwright.sync_api import Playwright, sync_playwright
async def connect_to_browser(channel: str) -> Playwright:
playwright = await sync_playwright().start()
browser = await playwright.connect_over_websocket(url=channel)
return playwright
# 连接已经打开的浏览器,需要提供 WebSocket URL
playwright = await connect_to_browser("ws://127.0.0.1:1234/devtools/browser/xxxxx")
```
阅读全文