playwright--自动化(一):快速上手
Playwright为现代 Web 应用程序提供可靠的端到端测试。
在JavaScript 和 TypeScript、Python、.NET和Java 中都可以使用 Playwright 本人选择python
快速上手
安装
pip install --upgrade pip
pip install playwright
playwright install
playwright 这个用来安装适用的浏览器二进制文件如:Chromium、Firefox 和 WebKit 如果不想下载谷歌开发版 可以使用自己的谷歌浏览器 其他浏览器只能用特等的开发版
playwright 默认安装位置
windows: %USERPROFILE%\AppData\Local\ms-playwright
macos: ~/Library/Caches/ms-playwright
linux: ~/.cache/ms-playwright
详细请查看:https://playwright.dev/python/docs/browsers/#installing-browsers
用法
playwright 同步
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=False,slow_mo=50)
page = browser.new_page()
page.goto("https://www.baidu.com")
print(page.title())
browser.close()
headless=False 不使用无头浏览模式,
slow_mo=50 执行速度
playwright 异步
import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
await page.goto("http://playwright.dev")
print(await page.title())
await browser.close()
asyncio.run(main())
详细请查看:https://playwright.dev/python/docs/intro
想了解其他的用法的可以直接评论出来!!!
下章代理使用!!!
👇👇👇