因此,我很难让selenium使用无头驱动程序,特别是PhantomJS。我试图让它在Ubuntu get服务器(Ubuntu14.04.2LTS)上工作。
从python解释器(Python2.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用户身份登录。幻影are目录的权限如下:
drwxr-sr-x 2 root staff 4096 Sep 9 06:58 phantomjs
对于幻影/webdriver.py:
-rw-r--r-- 1 root root 2985 Sep 9 06:58 webdriver.py
我已经确认selenium已经安装并更新了(pip安装selenium -升级)。它安装在:
/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),但也有类似的问题。
我愿意接受任何建议,如果需要的话,我不介意换司机。
提前感谢您的帮助。
发布于 2015-10-09 11:38:19
我和你有同样的问题,有同样的错误。我试图在openSuse服务器上安装它。最后,我安装了PhantomJS表单源代码-unfortunately,但没有成功。我的工作方式是通过npm安装幻影。
sudo npm install -g phantomjs
发布于 2015-09-20 00:52:29
所以通过包管理器安装幻影似乎可以修复它..。
sudo apt-get install phantomjs
总之,希望上面的过程能帮助其他有同样问题的人。
https://stackoverflow.com/questions/32491274
复制相似问题