そのため、セレンをヘッドレスドライバー、特に 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
私は見てきました:
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 - セレンをアンインストールして v2.37 をインストールしましたが、うまくいきませんでした。最新バージョンを再インストールしましたが、それでもうまくいきません。
さらに、いくつかの他のリンクは、ほとんどが executable_path を指定することを推奨しているようです。
chromedriverを使用して、ローカルでホストされているサーバー(OSX上)でプログラムをテストしています。私は実際にそのために Splinter ( https://splinter.readthedocs.org/en/latest/#headless-drivers ) を使用しており、他のヘッドレス ドライバー (django および zope.testbrowser) を試しましたが、同様の問題がありました。
必要に応じてドライバーを変更してもかまいません。
助けてくれてありがとう。