FreeBSD Selenium PhantomJS - 无法连接到服务

FreeBSD Selenium PhantomJS - 无法连接到服务

我坚持用 selenium 运行 PhantomJS。所以我准备了一个 FreeBSD Jail 并通过 ports 安装了 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')

相关内容