Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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] 
                I managed to find out why it was showing data[0] with the value ' ', the elements I was looking for are inside divs, and one of them has a dynamic class, it has 3 classes, and then I modified the code so that it appears class in this div he run the code, and it worked
– antoniocsk8
                Apr 13, 2022 at 19:53
                But compiling the code manually, I can get a result in which the data[0] is filled, but I have to compile it about 5 times, this project is about 1 roulette, and the data[0] is the last number that came out in it,
– antoniocsk8
                Apr 13, 2022 at 16:37
                Based on your code it looks like data[0] is always the same. In the while-loop you keep evaluating the same expression.
– juhat
                Apr 13, 2022 at 16:42
                The data[0] is the most recent entry, it's information that updates in about 25 seconds, so it always changes, so when the data[0] is [' '], it's probably because it hasn't loaded yet
– antoniocsk8
                Apr 13, 2022 at 17:18
                In that case you need to add wait time inside your while-loop because your loop is running thousands of times per second which is too much to handle and results in error.
– juhat
                Apr 13, 2022 at 17:21
                I managed to find out why it was showing data[0] with the value ' ', the elements I was looking for are inside divs, and one of them has a dynamic class, it has 3 classes, and then I modified the code so that it appears class in this div it run the code, and it worked, thanks
– antoniocsk8
                Apr 13, 2022 at 19:53
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.