0%

Playwright 的安装

Playwright 是微软开源的自动化测试工具,也可以用作网络爬虫。

相关链接

  • GitHub:https://github.com/microsoft/playwright
  • 官方文档:https://playwright.dev/python/docs/intro

安装方法

pip 安装

推荐使用 pip3 安装,命令如下:

1
2
3
pip3 install --upgrade pip
pip3 install playwright
playwright install

命令执行完毕之后即可完成安装,其中最后一条命令,Playwright 会完成一些初始化的工作,比如下载必要的浏览器和配置对应驱动、环境变量等。

conda 安装

也可以使用 conda 安装,安装命令如下:

1
2
3
4
conda config --add channels conda-forge
conda config --add channels microsoft
conda install playwright
playwright install

效果是一样的。

验证安装

安装完成之后,可以在 Python 命令行下测试。

1
2
$ python3
>>> import playwright

如果没有错误报出,则证明库已经安装好了。