Playwright运行报错的解决

未安装浏览器报错

playwright._impl._api_types.Error: Executable doesn't exist at /home/deploy/.cache/ms-playwright/firefox-1403/firefox/firefox
╔════════════════════════════════════════════════════════════╗
║ Looks like Playwright was just installed or updated.       ║
║ Please run the following command to download new browsers: ║
║                                                            ║
║     playwright install                                     ║
║                                                            ║
║ <3 Playwright Team                                         ║
╚════════════════════════════════════════════════════════════╝

这个错误是因为没有安装playwright的浏览器导致的,需要输入以下命令安装浏览器

playwright install
## 或者
python -m playwright install

## 以上命令会安装所有浏览器,如果只需要安装一个浏览器比如firefox
python -m playwright install firefox

未安装依赖报错

playwright._impl._api_types.Error: 
╔══════════════════════════════════════════════════════╗
║ Host system is missing dependencies to run browsers. ║
║ Missing libraries:                                   ║
║     libgtk-3.so.0                                    ║
║     libgdk-3.so.0                                    ║
║     libXcomposite.so.1                               ║
║     libXdamage.so.1                                  ║
║     libXfixes.so.3                                   ║
║     libXrandr.so.2                                   ║
║     libXtst.so.6                                     ║
║     libpangocairo-1.0.so.0                           ║
║     libpango-1.0.so.0                                ║
║     libatk-1.0.so.0                                  ║
║     libcairo-gobject.so.2                            ║
║     libcairo.so.2                                    ║
║     libgdk_pixbuf-2.0.so.0                           ║
║     libXcursor.so.1                                  ║
║     libXi.so.6                                       ║
╚══════════════════════════════════════════════════════╝

这是因为没有安装playwright的依赖导致的问题,可以执行下面的命令来安装

# centos
yum -y install libappindicator-gtk3
yum -y install liberation-fonts

# ubuntu/debian
apt-get install -y gstreamer1.0-libav libnss3-tools libatk-bridge2.0-0 libcups2-dev libxkbcommon-x11-0 libxcomposite-dev libxrandr2 libgbm-dev libgtk-3-0

# ubuntu/debian也可以执行来安装依赖
python -m playwright install --with-deps
posted @ 2023-06-12 14:03  写python的叮叮叮  阅读(9419)  评论(0)    收藏  举报