无法建立新的连接:[WinError 10061],循环从网站获取数据

发布于 2025-01-21 03:43:32 字数 6730 浏览 0 评论 0原文

我正在编写代码,我需要每当第一个值等于“ ”时,它就会再次搜索,直到该值 >= 1,一旦达到,代码必须等待 19.97 秒才能返回搜索。

因为在这20秒的时间间隔内我将导出这些数据,并且它将是连续的数据,总是会覆盖过去的

from asyncio.windows_events import NULL
from ctypes.wintypes import PINT
from logging import root
from tkinter import N
from hyperlink import URL
from selenium import webdriver
import selenium
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located
import time

url = "https://blaze.com/pt/games/double"

#absolute path
firefox_driver_path = "/Users/Antônio/Desktop/roletarobo/geckodriver.exe"
firefox_options = Options()
firefox_options.add_argument("--headless")

webdriver = webdriver.Firefox(
    executable_path = firefox_driver_path,
    options = firefox_options
)
with webdriver as driver:
    # timeout
    wait = WebDriverWait(driver, 20)

    # retrieve data
    driver.get(url)

    #wait
    wait.until(presence_of_element_located((By.ID, "roulette-recent")))

    results = driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")
    for quote in results:
      quoteArr = quote.text.split('\n')

    print([my_elem.text for my_elem in driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")][:17])
    
    data = [my_elem.text for my_elem in driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")][:17]

while data[0] == '' or []:

    data = [my_elem.text for my_elem in driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")][:17]
    
else:
  time.sleep(19.97)


但是我只得到第一个结果,它无法再次连接到服务器

webdriver = webdriver.Firefox(
['', '1', '11', '4', '7', '3', '13', '6', '11', '4', '2', '3', '10', '3', '8', '12', '10']
Traceback (most recent call last):
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\connection.py", line 95, in create_connection
    raise err
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] Nenhuma conexão pôde ser feita porque a máquina de destino as recusou ativamente

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1328, in _send_request       
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1037, in _send_output        
    self.send(msg)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 975, in send
    self.connect()
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 205, in connect
    conn = self._new_conn()
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000001EF5D9A9D20>: Failed to establish a new connection: [WinError 10061] Nenhuma conexão pôde ser feita porque a máquina de destino as recusou ativamente

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\Antônio\Desktop\roletarobo\roleta01.py", line 46, in <module>
    data = [my_elem.text for my_elem in driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")][:17]    
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1283, in find_elements
    return self.execute(Command.FIND_ELEMENTS, {
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 423, in execute
    response = self.command_executor.execute(driver_command, params)
uest_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\poolmanager.py", line 375, in urlopen    response = conn.urlopen(method, u.request_uri, **kw)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=57822): Max retries exceeded with url: /session/7a95ebe0-af22-4cd1-94be-e68b9e6ecb5a/elements (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001EF5D9A9D20>: Failed to establish a new connection: [WinError 10061] 

I'm making a code and I need that whenever the first value is equal to ' ', it searches again until this value is >= 1, once it is, the code must wait 19.97 seconds to return the searches.

Because in this 20 second interval I will export this data, and it will be continuous data that will always overwrite the past

from asyncio.windows_events import NULL
from ctypes.wintypes import PINT
from logging import root
from tkinter import N
from hyperlink import URL
from selenium import webdriver
import selenium
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located
import time

url = "https://blaze.com/pt/games/double"

#absolute path
firefox_driver_path = "/Users/Antônio/Desktop/roletarobo/geckodriver.exe"
firefox_options = Options()
firefox_options.add_argument("--headless")

webdriver = webdriver.Firefox(
    executable_path = firefox_driver_path,
    options = firefox_options
)
with webdriver as driver:
    # timeout
    wait = WebDriverWait(driver, 20)

    # retrieve data
    driver.get(url)

    #wait
    wait.until(presence_of_element_located((By.ID, "roulette-recent")))

    results = driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")
    for quote in results:
      quoteArr = quote.text.split('\n')

    print([my_elem.text for my_elem in driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")][:17])
    
    data = [my_elem.text for my_elem in driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")][:17]

while data[0] == '' or []:

    data = [my_elem.text for my_elem in driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")][:17]
    
else:
  time.sleep(19.97)


But I'm only getting the first result, it's not able to connect to the server again

webdriver = webdriver.Firefox(
['', '1', '11', '4', '7', '3', '13', '6', '11', '4', '2', '3', '10', '3', '8', '12', '10']
Traceback (most recent call last):
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\connection.py", line 95, in create_connection
    raise err
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] Nenhuma conexão pôde ser feita porque a máquina de destino as recusou ativamente

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1328, in _send_request       
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1037, in _send_output        
    self.send(msg)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 975, in send
    self.connect()
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 205, in connect
    conn = self._new_conn()
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000001EF5D9A9D20>: Failed to establish a new connection: [WinError 10061] Nenhuma conexão pôde ser feita porque a máquina de destino as recusou ativamente

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\Antônio\Desktop\roletarobo\roleta01.py", line 46, in <module>
    data = [my_elem.text for my_elem in driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")][:17]    
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1283, in find_elements
    return self.execute(Command.FIND_ELEMENTS, {
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 423, in execute
    response = self.command_executor.execute(driver_command, params)
uest_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\poolmanager.py", line 375, in urlopen    response = conn.urlopen(method, u.request_uri, **kw)
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "C:\Users\Antônio\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=57822): Max retries exceeded with url: /session/7a95ebe0-af22-4cd1-94be-e68b9e6ecb5a/elements (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001EF5D9A9D20>: Failed to establish a new connection: [WinError 10061] 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帥小哥 2025-01-28 03:43:33

问题在于这一行:

while data[0] == '' or []:

您的数据[0]始终'' - &gt;循环永远运行,导致maxRetryError

Problem is with this line:

while data[0] == '' or []:

Your data[0] is always '' -> the loop runs forever which results in the MaxRetryError.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文