7

そのため、セレンをヘッドレスドライバー、特に PhantomJS で動作させるのに問題があります。Ubuntu Webサーバー(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) を試しましたが、同様の問題がありました。

必要に応じてドライバーを変更してもかまいません。

助けてくれてありがとう。

4

2 に答える 2

12

私はあなたと同じエラーで同じ問題を抱えていました。openSuse サーバーにインストールしようとしました。最終的に PhantomJS フォーム ソースをインストールしましたが、残念ながら成功しませんでした。私にとってうまくいった方法は、npm経由でPhantomjsをインストールすることでした

sudo npm install -g phantomjs
于 2015-10-09T11:38:19.583 に答える