我是编程新手,可能是python2尝试用selenium加载firefox时出现错误,请问如何解决此错误? 我正在Windows 7 64bit,python2.7,firefox58上运行。 这是下面的代码:
from selenium import webdriver
import time
p = proxy
pp = port
ua = user_agent
fp = webdriver.FirefoxProfile()
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http",p)
fp.set_preference("network.proxy.http_port",pp)
fp.set_preference("network.proxy.ssl",p)
fp.set_preference("network.proxy.ssl_port",pp)
fp.set_preference("general.useragent.override",ua)
fp.set_preference("media.peerconnection.ice.proxy_only", True)
fp.update_preferences()
driver = webdriver.Firefox(firefox_profile=fp)
driver.get(url)
time.sleep(5)
driver.quit()
driver = webdriver.Firefox(firefox_profile=fp)
File "C:\Python2\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 174, in __init__
keep_alive=True)
File "C:\Python2\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Python2\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Python2\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Python2\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 374, in execute
return self._request(command_info[0], url, body=data)
File "C:\Python2\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "C:\Python2\lib\site-packages\urllib3\request.py", line 72, in request
**urlopen_kw)
File "C:\Python2\lib\site-packages\urllib3\request.py", line 150, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "C:\Python2\lib\site-packages\urllib3\poolmanager.py", line 324, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "C:\Python2\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Python2\lib\site-packages\urllib3\util\retry.py", line 368, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Python2\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Python2\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "C:\Python2\lib\site-packages\urllib3\connectionpool.py", line 306, in _raise_timeout
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
ReadTimeoutError: HTTPConnectionPool(host='127.0.0.1', port=49676): Read timed out. (read timeout=<object object at 0x01F084B8>)