簡體   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