🎭 适用于 Python 的 Playwright
Playwright 是一个 Python 库,用于使用单一 API 自动化 Chromium、Firefox 和 WebKit 浏览器。Playwright 提供的自动化功能始终保持最新、功能强大、可靠且快速。了解 Playwright 的优势。
Linux | macOS | Windows | |
---|---|---|---|
Chromium 128.0.6613.18 | ✅ | ✅ | ✅ |
WebKit 18.0 | ✅ | ✅ | ✅ |
Firefox 128.0 | ✅ | ✅ | ✅ |
文档
https://playwright.dev/python/docs/intro
API 参考
https://playwright.dev/python/docs/api/class-playwright
示例
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
for browser_type in [p.chromium, p.firefox, p.webkit]:
browser = browser_type.launch()
page = browser.new_page()
page.goto('http://playwright.dev')
page.screenshot(path=f'example-{browser_type.name}.png')
browser.close()
import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
for browser_type in [p.chromium, p.firefox, p.webkit]:
browser = await browser_type.launch()
page = await browser.new_page()
await page.goto('http://playwright.dev')
await page.screenshot(path=f'example-{browser_type.name}.png')
await browser.close()
asyncio.run(main())
其他语言
更喜欢使用其他编程语言?Playwright 也提供以下版本: