文 | 某某白米饭
来源:Python 技术「ID: pythonall」
Playwright 是微软出的一款自动化测试工具,在做爬虫的时候,只需要点点点操作就能将代码录下来,用 python 脚本运行。有非常强大的 API,完全满足爬虫的需要。
安装
需要安装 playwright 第三方模块和Chromium、Firefox、WebKit等浏览器的驱动文件。
pip install playwright
python -m playwright install
录制
playwright 在抓取页面的时候是不需要太多写代码的,录制就完事了。首先看看有哪些命令参数:
python -m playwright codegen --help
这里有好几个选项:
-o:输出的代码文件的名称
--target:语言:默认为 python,python-async 自动生成的是异步模块的代码
-b:用的浏览器
--time:页面超时时间
将脚本文件存放在 D 盘的 playwright_demo.py 中。
# 命令行键入
python -m playwright codegen -o D:\playwright_demo.py