首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Selenium Python (PhantomJS)无法工作

Selenium Python (PhantomJS)无法工作
EN

Stack Overflow用户
提问于 2015-09-10 00:42:44
回答 2查看 9.4K关注 0票数 7

因此,我很难让selenium使用无头驱动程序,特别是PhantomJS。我试图让它在Ubuntu get服务器(Ubuntu14.04.2LTS)上工作。

从python解释器(Python2.7.6)运行以下命令提供:

代码语言:javascript
运行
复制
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

我也试过:

代码语言:javascript
运行
复制
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路径中:

代码语言:javascript
运行
复制
import sys
sys.path.append("/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/")

我目前以root用户身份登录。幻影are目录的权限如下:

代码语言:javascript
运行
复制
drwxr-sr-x  2 root staff 4096 Sep  9 06:58 phantomjs

对于幻影/webdriver.py:

代码语言:javascript
运行
复制
-rw-r--r--  1 root root  2985 Sep  9 06:58 webdriver.py

我已经确认selenium已经安装并更新了(pip安装selenium -升级)。它安装在:

代码语言:javascript
运行
复制
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/

print selenium.__version__
2.47.1

我看过:

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

我愿意接受任何建议,如果需要的话,我不介意换司机。

提前感谢您的帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-09 11:38:19

我和你有同样的问题,有同样的错误。我试图在openSuse服务器上安装它。最后,我安装了PhantomJS表单源代码-unfortunately,但没有成功。我的工作方式是通过npm安装幻影。

代码语言:javascript
运行
复制
sudo npm install -g phantomjs
票数 12
EN

Stack Overflow用户

发布于 2015-09-20 00:52:29

所以通过包管理器安装幻影似乎可以修复它..。

代码语言:javascript
运行
复制
sudo apt-get install phantomjs

总之,希望上面的过程能帮助其他有同样问题的人。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32491274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档