gpt4 book ai didi

python - Selenium ConnectionRefusedError : [WinError 10061] in python 3

转载 作者:太空宇宙 更新时间:2023-11-04 02:28:07 27 4
gpt4 key购买 nike

我有一个 python 程序,它使用 selenium 访问站点并获取元素的值。现在,我有一个字典列表,每个字典都有一个 url 参数。我遍历列表并从每个字典转到 url。问题是在循环的第一次运行之后它给了我一个错误:

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

Traceback (most recent call last):
File "C:\Users\Me\Desktop\mfile\getfuncs.py", line 15, in <module>
browser.get(newurl)
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 324, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 310, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 466, in execute
return self._request(command_info[0], url, body=data)
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 489, in _request
self._conn.request(method, parsed_url.path, body, headers)
File "C:\Users\Me\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\Me\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\Me\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\Me\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 964, in send
self.connect()
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 936, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 724, in create_connection
raise err
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 713, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

我在一篇类似的文章中读到“在交互式 shell 中启动后不得关闭浏览器”,但是当我删除行 browser.quit() 时,它给出了另一个错误:

ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

Traceback (most recent call last):
File "C:\Users\Me\Desktop\mfile\getfuncs.py", line 15, in <module>
browser.get(newurl)
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 324, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 310, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 466, in execute
return self._request(command_info[0], url, body=data)
File "C:\Users\Me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 489, in _request
self._conn.request(method, parsed_url.path, body, headers)
File "C:\Users\Me\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\Me\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\Me\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\Me\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1065, in _send_output
self.send(chunk)
File "C:\Users\Me\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

我还检查了我的防火墙,它没有阻止 selenium。

这是我的代码:

from selenium import webdriver

browser = webdriver.Chrome()

things = [list of dicts]
results = []

for item in things:
browser.get(item['url'])

box = browser.find_element_by_id('some element')
content = box.get_attribute('value')

results.append(content)
browser.quit()

是什么导致了这个问题?

最佳答案

我发现了问题; browser.quit() 在不应该的时候进入了循环。

关于python - Selenium ConnectionRefusedError : [WinError 10061] in python 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49846883/

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