gpt4 book ai didi

python - Splinter Selenium Phantomjs 驱动程序实例化失败

转载 作者:太空宇宙 更新时间:2023-11-03 12:05:47 25 4
gpt4 key购买 nike

我正在尝试使用 Python + Splinter + Selenium + PhantomJS 进行基本测试,但我无法启动 phantomjs 浏览器。 (尽管 Chrome 和 Firefox 驱动程序工作正常。)当我运行时:

from splinter import Browser

b = Browser('phantomjs')

我得到错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/splinter/browser.py", line 63, in Browser
return driver(*args, **kwargs)
File "/Library/Python/2.7/site-packages/splinter/driver/webdriver/phantomjs.py", line 32, in __init__
self.driver = PhantomJS(desired_capabilities=capabilities, **kwargs)
File "/Library/Python/2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 56, in __init__
desired_capabilities=desired_capabilities)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 87, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 141, in start_session
'desiredCapabilities': desired_capabilities,
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 199, in execute
response = self.command_executor.execute(driver_command, params)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 395, in execute
return self._request(command_info[0], url, body=data)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 463, in _request
resp = opener.open(request, timeout=self._timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1227, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>

此外,当我运行时:

from selenium import webdriver

d = webdriver.PhantomJS()

我得到了本质上相同的错误。

看起来 PhantomJS 正在使用 Remote 驱动程序连接到远程服务器,但 splinter 并未启动用于 PhantomJS 连接的 selenium(?)服务器。我不介意进入 splinter(?) 的源代码并更改一些内容以使其工作。但是,我无法确定什么可以解决这个问题。

或者,我是否需要手动启动服务器以供 PhantomJS 连接?

(作为引用,Ruby + Cucumber + Capybara + Poltergeist 在我的盒子上运行良好。)这是我的软件的配置。

$ python --version
Python 2.7.10

$ pip show splinter | grep Version
Metadata-Version: 1.1
Version: 0.7.3

$ pip show selenium | grep Version
Metadata-Version: 2.0
Version: 2.47.3

$ phantomjs -v
2.0.0

$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.10.5
BuildVersion: 14F27

最佳答案

只是想分享一下 phantomjs + splinter 在我的机器上使用以下配置可以很好地工作:

~ $ python --version
Python 2.7.11

~ $ pip show splinter | grep Version
Metadata-Version: 1.1
Version: 0.7.3

~ $ pip show selenium | grep Version
Metadata-Version: 2.0
Version: 2.47.3

~ $ phantomjs -v
2.0.0

~ $ sw_vers
ProductName: Mac OS X
ProductVersion: 10.11
BuildVersion: 15A284

关于python - Splinter Selenium Phantomjs 驱动程序实例化失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32772568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com