使用 python 和 selenium 连接到 phantomJs webdriver 时遇到问题

2023-11-27

我正在尝试在使用 selenium 和 phantomjs webdriver 的 Linux 服务器上运行 python 脚本;但是,我不断收到以下错误消息:

selenium.common.exceptions.WebDriverException: Message: Service /home/ubuntu/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs unexpectedly exited. Status code was: 127

这是一个失败并生成此错误的简单测试脚本:

import selenium
from selenium import webdriver

driver = webdriver.PhantomJS(executable_path='/home/ubuntu/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs')

调用路径上的文件,返回:

file  /home/ubuntu/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
/home/ubuntu/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=d0f2a21ff9e0b82113a2095e7cbca7dceaba88fb, stripped

有谁知道我如何启动并运行这个脚本?我已经阅读了看似类似的 stackoverflow 问题,并尝试应用建议的解决方案,例如通过 npm 重新安装 phantom 并使用 sudo 执行脚本,但没有运气。如果我可以提供更多信息,请告诉我。


sudo apt-get install libfontconfig

这解决了我的问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 python 和 selenium 连接到 phantomJs webdriver 时遇到问题 的相关文章

随机推荐