FreeBSD Selenium PhantomJS - サービスに接続できません。

FreeBSD Selenium PhantomJS - サービスに接続できません。

私はPhantomJSを実行するためにセレンを使用する必要があると主張します。だから私はFreeBSD Jailを準備し、ポートを介してphantomjsをインストールしました。

whereis phantomjs
> phantomjs: /usr/local/bin/phantomjs /usr/ports/lang/phantomjs

/usr/local/bin/phantomjs -v
> 2.0.0

私のスクリプトは次のとおりです

from selenium import webdriver

PHANTOM_PATH = '/usr/local/bin/phantomjs'

driver = webdriver.PhantomJS(executable_path=PHANTOM_PATH)
driver.set_window_size(1024, 768)
driver.get('https://google.com/')
driver.save_screenshot('screen.png')
driver.quit()

ところで、このようなエラーが発生し続け、解決策が見つかりません。

File "driver.py", line 5, in <module>
driver = webdriver.PhantomJS(PHANTOM_PATH)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__
self.service.start()
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 88, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /usr/local/bin/phantomjs

Exception AttributeError: AttributeError("'NoneType' object has no attribute 'close'",) in <bound method Service.__del__ of <selenium.webdriver.phantomjs.service.Service object at 0x8007981d0>> ignored

ベストアンサー1

「service_log_path」を明示的に指定してください。

driver = webdriver.PhantomJS(executable_path='/usr/local/bin/phantomjs', service_log_path='/tmp/ghostdriver.log')

おすすめ記事