Playwright 需要 Python 3.7 或更高版本。Chromium、Firefox 和 WebKit 的浏览器二进制文件可在 3 个平台(Windows、macOS、Linux)上运行
安装Playwright。第一步是更新pip。第二步是安装Playwright第三方库,第三步是安装Playwright需要的浏览器,不指定安装某类浏览器的话,默认是全部安装。
pip install --upgrade pip
pip install playwright
playwright install
这些命令下载 Playwright 包并为 Chromium、Firefox 和 WebKit 安装浏览器二进制文件
conda config --add channels conda-forge
conda config --add channels microsoft
conda install playwright
playwright install
安装后,您可以import
在 Python 脚本中进行 Playwright,并启动 3 个浏览器( 和 )中的chromium
任何firefox
一个webkit
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto("http://playwright.dev")