Selenium Python无头Webdriver(PhantomJS)不工作

cdf*_*dfh 7 python linux selenium phantomjs splinter

所以我很难让硒与无头驱动器,特别是PhantomJS一起工作.我试图让它在Ubuntu网络服务器(Ubuntu 14.04.2 LTS)上运行.

从python解释器(Python 2.7.6)运行以下命令给出:

from selenium import webdriver
driver = webdriver.PhantomJS()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/service.py", line 76, in start
    raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e)
selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghostdriver: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

driver = webdriver.PhantomJS(executable_path="/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/service.py", line 76, in start
    raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e)
selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghostdriver: [Errno 13] Permission denied
Run Code Online (Sandbox Code Playgroud)

我还将它添加到python路径:

import sys
sys.path.append("/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/")
Run Code Online (Sandbox Code Playgroud)

我目前以root身份登录.phantomjs目录的权限是:

drwxr-sr-x  2 root staff 4096 Sep  9 06:58 phantomjs
Run Code Online (Sandbox Code Playgroud)

对于phantomjs/webdriver.py:

-rw-r--r--  1 root root  2985 Sep  9 06:58 webdriver.py
Run Code Online (Sandbox Code Playgroud)

我已经确认安装了selenium并且是最新的(pip install selenium --upgrade).它安装在:

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/

print selenium.__version__
2.47.1
Run Code Online (Sandbox Code Playgroud)

我看过:

我一直在使用chromedriver在本地托管的服务器(OSX上)上测试我的程序.我实际上正在使用Splinter(https://splinter.readthedocs.org/en/latest/#headless-drivers),并尝试过其他无头驱动程序(django和zope.testbrowser),但也有类似的问题.

我对任何建议持开放态度,如果需要,我不介意更换驱动程序.

在此先感谢您的帮助.

Luk*_*ski 12

我遇到了和你一样的错误.我试图在openSuse Server上安装它.我最终安装了PhantomJS表单源 - 但是没有成功.对我有用的方法是通过npm安装Phantomjs

sudo npm install -g phantomjs
Run Code Online (Sandbox Code Playgroud)