【问题标题】:Trouble connecting to phantomJs webdriver using python and selenium使用 python 和 selenium 连接到 phantomJs webdriver 时出现问题
【发布时间】:2016-11-15 06:28:34
【问题描述】:

我正在尝试在使用 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

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

【问题讨论】:

    标签: python linux selenium phantomjs


    【解决方案1】:
    sudo apt-get install libfontconfig
    

    这解决了我的问题。

    【讨论】:

    • 我尝试了这个解决方案,但我仍然得到相同的状态代码:127 错误消息。