[英]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
我看过:
https://superuser.com/questions/674322/python-selenium-phantomjs-unable-to-start-phantomjs-with-ghostdriver - Windows特定但没有运气遵循类似的建议。
在背景中使用Selenium - 答案表明PhatomJS具有完整路径。
https://code.google.com/p/selenium/issues/detail?id=6736 - 我卸载了selenium并安装了v2.37,没有运气。 重新安装最新版本仍然没有运气。
加上一些其他链接,大多数似乎建议指定executable_path。
我一直在使用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.