sssccc5433

导航

 

首先conda环境,利用国内镜像源安装playwright
关于版本,参考网上信息,python最好选择3.9-3.11版本,playwright不要最新版

conda create -n webtest python=3.10
pip install playwright==1.40.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

Playwright 每个版本都绑定特定浏览器二进制版本;现在的 Playwright 1.40.0 对应的是 Chromium revision 1091 / Chromium 120.0.6099.28,不是任意 Chromium 都能用。官方也说明,每个 Playwright 版本需要对应的浏览器二进制文件。
接下来直接用 npmmirror 安装 Chromium(试过用国内其他镜像源,总是报错)

# 设置国内镜像
$env:PLAYWRIGHT_DOWNLOAD_HOST = "https://npmmirror.com/mirrors/playwright"
# 只安装 chromium,不要直接 playwright install 全量安装
python -m playwright install chromium

注意:python -m playwright install # 安装全部浏览器(谷歌、火狐等,没必要,还满)

接下来就可以直接操作浏览器来录制了:
playwright codegen https://www.baidu.com/

posted on 2026-06-28 17:02  长沙辣子  阅读(274)  评论(0)    收藏  举报