python3+selenium 3.13 + geckodriver 21.0,提示ConnectionResetError,切换会较低版本的driver即可
Posted csj2018
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3+selenium 3.13 + geckodriver 21.0,提示ConnectionResetError,切换会较低版本的driver即可相关的知识,希望对你有一定的参考价值。
学习selenium时,如果sleep时间大于等于5秒,就会提示ConnectionResetError: [Errno 54] Connection reset by peer。
换成chrome浏览器,可以正常运行。
#demo.py
from selenium import webdriver
from time import sleep, ctime
#chrome
#driver = webdriver.Chrome(executable_path=‘//Users/csj/Desktop/seleniumdriver/chromedriver/chromedriver‘)
#Firefoxdriver 21.0
driver = webdriver.Firefox(executable_path=‘//Users/csj/Desktop/seleniumdriver/firefoxdriver/21.0/geckodriver‘)
#Firefoxdriver 20.1
#driver = webdriver.Firefox(executable_path=‘//Users/csj/Desktop/seleniumdriver/firefoxdriver/20.1/geckodriver‘)
#Firefoxdriver 20.0
#driver = webdriver.Firefox(executable_path=‘//Users/csj/Desktop/seleniumdriver/firefoxdriver/20.0/geckodriver‘)
#Firefox 19.1
#driver = webdriver.Firefox(executable_path=‘//Users/csj/Desktop/seleniumdriver/firefoxdriver/19.1/geckodriver‘)
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
print(ctime())
sleep(5)
print(ctime())
driver.find_element_by_id("kw").send_keys("selenium")
driver.close()```
使用Firefoxdriver 21.0,报如下错误:
Traceback (most recent call last):
File "/Users/csj/PycharmProjects/untitled/demo.py", line 13, in <module>
driver.find_element_by_id("kw").send_keys("selenium")
File "/Users/csj/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 353, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "/Users/csj/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 957, in find_element
‘value‘: value})[‘value‘]
File "/Users/csj/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
response = self.command_executor.execute(driver_command, params)
File "/Users/csj/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 472, in execute
return self._request(command_info[0], url, body=data)
File "/Users/csj/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 496, in _request
resp = self._conn.getresponse()
File "/Users/csj/anaconda/lib/python3.6/http/client.py", line 1331, in getresponse
response.begin()
File "/Users/csj/anaconda/lib/python3.6/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/Users/csj/anaconda/lib/python3.6/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE