E
E
Ernest Vardanyan2020-05-10 04:09:44
Python
Ernest Vardanyan, 2020-05-10 04:09:44

How to specify the correct condition when parsing?

If a NoSuchElementException error occurs, I would like the code to continue parsing, but it stops, I parse the scoreboard, and if, for example, I parse round 3, but it doesn’t exist yet, it parses 1.2 and gives an error, but instead of an error, it starts parsing another battle and his rounds, and so on until the end. Parsing round 1-2 are variables ('fd' , 'fe'), the code continues and everything is the same in the second, the current variables are different and a couple of other elements

from selenium import webdriver
import time

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)



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('ПАРСИМ ТАБЛО.......')

fd=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(fd)

fe=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(fe)

betwin1=browser.find_element_by_xpath('//*[@id="allBetsTable"]/div[1]/div[1]/div/div[2]').text
print(betwin1)

betfinish1=browser.find_element_by_xpath('//*[@id="allBetsTable"]/div[1]/div[3]/div/div[2]').text
print(betfinish1)

bettime1=browser.find_element_by_xpath('//*[@id="allBetsTable"]/div[2]/div[1]/div/div[2]').text
print(bettime1)

browser.close()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-05-10
@LazyTalent

Exceptions in python. try - except for ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question