我正在用"Automate the by with 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')
当我第一次编写>>> browser.get('http://inventwithpython.com')
时,出现了这个错误。当我第二次编写此命令时,Mozilla Firefox浏览器会打开所需的网页。当我第三次编写命令时,ConnectionAbortedError再次发生,依此类推--写入命令的奇数次(1,3,...)结果是ConnectionAbortedError和偶数倍(2,4,...)没有错误地通过。我试图关闭杀毒软件和防火墙,但没有帮助。请帮我解决这个问题。附言:我使用的是Windows 10操作系统。
发布于 2018-07-09 07:26:37
我是《用Python自动化无聊的东西》一书的作者。我在Windows10机器上也遇到了这个错误。根据这个StackOverflow答案,https://stackoverflow.com/a/51005821/1893164,这似乎是geckodriver 0.21.0的一个问题。
对我有效的解决方法是安装旧版本的geckodriver,0.20.1,您可以从这里下载:https://github.com/mozilla/geckodriver/releases/tag/v0.20.1
https://stackoverflow.com/questions/51160562
复制相似问题