繁体   English   中英

Selenium Python无头Webdriver(PhantomJS)不工作

[英]Selenium Python Headless Webdriver (PhantomJS) Not Working

所以我很难让硒与无头驱动器,特别是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

我也尝试过:

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

我还将它添加到python路径:

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

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

drwxr-sr-x  2 root staff 4096 Sep  9 06:58 phantomjs

对于phantomjs / webdriver.py:

-rw-r--r--  1 root root  2985 Sep  9 06:58 webdriver.py

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

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

print selenium.__version__
2.47.1

我看过:

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

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

在此先感谢您的帮助。

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

sudo npm install -g phantomjs

所以通过包管理器安装phantomjs似乎解决了它...

sudo apt-get install phantomjs

无论如何,希望上面的过程可以帮助其他有同样问题的人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM