Answer the question
In order to leave comments, you need to log in
What is causing the TimeoutException and how to fix it?
I have a parser and it is in a function, I also call it 4 times, for each of the possible fights that may appear. I take each of these fights in the Exceptions and everything works. In order not to take a steam bath with the automatic launch of the code, I decided to use while True, perhaps because of this, the TimeoutException error appears. I want to know exactly what causes it, why and how to catch it right or just get rid of it.
from selenium import webdriver
import time
import telegram
def A():
код парсера
while True:
browser = webdriver.Chrome()
browser.maximize_window()
browser.get('ссылка')
try:
BOT_TOKEN = 'токен'
number2 = browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[5]/div/div[1]/div[1]/div').text
SS = number2.split()
if SS[0] == '0' and SS[1] == '0':
browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[5]/div/div[1]/div[1]/a').click()
time.sleep(5)
A()
except Exception:
pass
try:
BOT_TOKEN = 'токен'
number2 = browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[4]/div/div[1]/div[1]/div').text
SS = number2.split()
if SS[0] == '0' and SS[1] == '0':
browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[4]/div/div[1]/div[1]/a').click()
time.sleep(5)
A()
except Exception:
pass
try:
BOT_TOKEN = 'токен'
number2 = browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[3]/div/div[1]/div[1]/div').text
SS = number2.split()
if SS[0] == '0' and SS[1] == '0':
browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[3]/div/div[1]/div[1]/a').click()
time.sleep(5)
A()
except Exception:
pass
try:
BOT_TOKEN = 'токен'
number2 = browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[6]/div/div[1]/div[1]/div').text
SS = number2.split()
if SS[0] == '0' and SS[1] == '0':
browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[6]/div/div[1]/div[1]/a').click()
time.sleep(5)
A()
except Exception:
pass
browser.close()
time.sleep(15)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question