Answer the question
In order to leave comments, you need to log in
How to write an exception when parsing?
The fact that I scab has rounds, they can appear both after 20 and after 40 seconds, there are only 9 of them, I set the code for each of the 9 rounds, but if for example there are only 5 rounds, I scaven them and go to 6 and it doesn't exist, I catch this error:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: /html/body/div[2]/div[1]/div[2]/div/div/div[2] /div/div/div/div[1]/div[1]/div/div[2]/div/div/div[3]/div/section/div[1]/div[3]
I want he did not stop at the mistake and continued to parse the fight, that is, he moved on to names, coefficients and then to another fight and everything is the same, tell me please?
from selenium import webdriver
import time
import xlwt
from selenium.common.exceptions import NoSuchElementException
browser=webdriver.Firefox()
browser.maximize_window()
print('ИДЁТ ПАРСИНГ ПЕРВОГО БОЯ.........')
browser.get('https://one-xskbdc.world/ru/live/Mortal-Kombat/1252965-Mortal-Kombat-X/')
#Получаю имена бойцов
nameone1=browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[2]/div/div[1]/div[1]/a/span/div[1]').text
print(nameone1)
nametwo1=browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[2]/div/div[1]/div[1]/a/span/div[2]').text
print(nametwo1)
#Заходит на 1 бой
browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[2]/div/div[1]/div[1]/a/span/div[2]').click()
time.sleep(3)
#Закрывает окошко видео боя
browser.find_element_by_xpath('//*[@id="hottest_games"]/div/div[1]/div/div/div[2]/div/ul/li[1]/a').click()
time.sleep(3)
#Парсит счёт боя
score1=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[2]/div/div/div[2]/div[1]').text
print(score1)
score1_2=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[2]/div/div/div[2]/div[2]').text
print(score1_2)
print('Парсим табло.......')
Round1=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[3]/div/section/div[1]/div[1]').text
print(Round1)
Round2=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[3]/div/section/div[1]/div[2]').text
print(Round2)
Round3=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[3]/div/section/div[1]/div[3]').text
print(Round3)
Round4=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[3]/div/section/div[1]/div[4]').text
print(Round4)
Round5=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[3]/div/section/div[1]/div[5]').text
print(Round5)
Round6=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[3]/div/section/div[1]/div[6]').text
print(Round6)
Round7=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[3]/div/section/div[1]/div[7]').text
print(Round7)
Round8=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[3]/div/section/div[1]/div[8]').text
print(Round8)
Round9=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[3]/div/section/div[1]/div[9]').text
print(Round9)
#Победа в раунде
win_1name2=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[2]/div[1]/div[1]/div[1]/div/div[2]/div[1]/span[1]').text
print(win_1name2)
win_1name_kef2=browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[2]/div[1]/div[1]/div[1]/div/div[2]/div[1]/span[2]').text
print(win_1name_kef2)
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