Selenium webdriver 在Python3.6(selenium模块)中:ConnectionAbortedError:[WinError 10053]主机中的软件中止了已建立的连接

Selenium webdriver 在Python3.6(selenium模块)中:ConnectionAbortedError:[WinError 10053]主机中的软件中止了已建立的连接,selenium-webdriver,web-scraping,python-3.6,Selenium Webdriver,Web Scraping,Python 3.6,我正在学习《用Python自动化枯燥的东西》(由Al Sweigart撰写)一书中的Python,我对web抓取(第11章)有一个问题,即selenium模块。我正在用Python IDLE编写以下内容: >>> from selenium import webdriver >>> browser = webdriver.Firefox() # Here Windows command black window appears

我正在学习《用Python自动化枯燥的东西》(由Al Sweigart撰写)一书中的Python,我对web抓取(第11章)有一个问题,即selenium模块。我正在用Python IDLE编写以下内容:

>>> from selenium import webdriver
>>> browser = webdriver.Firefox() # Here Windows command black window appears
                                  # and Mozilla Firefox with blank page opens
>>> browser.get('http://inventwithpython.com')
    Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    browser.get('http://inventwithpython.com')
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 326, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 472, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 495, in _request
    self._conn.request(method, parsed_url.path, body, headers)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1065, in _send_output
    self.send(chunk)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 986, in send
    self.sock.sendall(data)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

>>> browser.get('http://inventwithpython.com')
来自selenium导入webdriver的
>
>>>browser=webdriver.Firefox()#此处显示Windows命令黑色窗口
#打开带有空白页面的Mozilla Firefox
>>>browser.get('http://inventwithpython.com')
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
browser.get('http://inventwithpython.com')
文件“C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第326行,在get中
self.execute(Command.GET,{'url':url})
文件“C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,执行中第312行
响应=self.command\u executor.execute(driver\u command,params)
文件“C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site packages\selenium\webdriver\remote\remote\u connection.py”,第472行,执行
返回self.\u请求(命令信息[0],url,正文=数据)
文件“C:\Users\forwa\AppData\Local\Programs\Python\36-32\lib\site packages\selenium\webdriver\remote\remote\u connection.py”,第495行,在请求中
self.\u conn.request(方法、解析的\u url.path、正文、标题)
请求中第1239行的文件“C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py”
self.\u发送\u请求(方法、url、正文、标题、编码\u分块)
文件“C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py”,第1285行,在发送请求中
self.endheaders(body,encode\u chunked=encode\u chunked)
文件“C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py”,第1234行,在endheaders中
self.\u发送\u输出(消息体,encode\u chunked=encode\u chunked)
文件“C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py”,第1065行,在发送输出中
self.send(块)
文件“C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py”,第986行,在send中
self.sock.sendall(数据)
ConnectionAbortedError:[WinError 10053]主机中的软件中止了已建立的连接
>>>browser.get('http://inventwithpython.com')
当我写
>>>browser.get('http://inventwithpython.com)
第一次出现错误时。当我第二次编写此命令时,Mozilla Firefox浏览器会打开所需的网页。当我第三次写入命令时,ConnectionBortedError再次出现,依此类推-写入命令的奇数次(1,3,…)导致ConnectionBortedError,偶数次(2,4,…)无误通过。 我试图关闭杀毒软件和防火墙,但没用。请帮我解决这个问题。
另外,我有Windows 10操作系统。

我是《用Python自动化无聊的东西》一书的作者。我在Windows10机器上也遇到了这个错误。根据这个StackOverflow答案,这似乎是geckodriver 0.21.0的一个问题


我的解决办法是安装geckodriver的旧版本0.20.1,您可以在这里下载:

我99%确定这与IDLE无关,因此删除了标记。为了100%确定,从命令提示符或开始菜单“Python3.6”下的“Python3.6”运行交互式python,并给出相同的命令。如果我错了,请加上“pythonidle”,并请给我留言。很抱歉,我对selenium一无所知。我尝试在Python 3.6.5下的命令窗口(Windows 10 PowerShell)中发出相同的命令。结果与Python IDLE中的结果相同。感谢您的反馈。太多人从不回复评论。非常感谢您的回复!我下载了geckodriver 0.20.1,然后将它放在C:\Users\User\AppData\Local\Programs\Python\Python36-32\selenium\webdriver文件夹中。然后我将这个文件夹添加到系统环境变量列表中。以下代码正常工作,没有出现错误:
>>来自selenium import webdriver
>>browser=webdriver.Firefox()
>browser.get('http://inventwithpython.com)