-1

I'm trying to parse the list of selenium python without results. What I want is to remove the 0-0 results of soccer matches. Example code:

driver.get("https://www.flashscore.com/match/Qs85KCdA/#h2h/overall")
time.sleep(3)

rows = driver.find_elements_by_xpath("//div[@class='h2h__row']")

for row in rows:
    results = row.find_element_by_xpath(".//span[@class='h2h__regularTimeResult']")
    date = row.find_element_by_xpath(".//span[@class='h2h__date']")
    print(results.text)
    print(date.text)

Output:

0 : 0
10.12.21
1 : 2
04.12.21
0 : 2
01.12.21
0 : 0
27.11.21
3 : 1
22.11.21
0 : 0
10.12.21
1 : 2
05.12.21
0 : 5
30.11.21
1 : 2
27.11.21
1 : 1
20.11.21
0 : 0
10.12.21
5 : 1
30.06.20
2 : 2
15.12.19
1 : 0
15.04.13
1 : 1
18.11.12

What i want is to don't print the 0:0. So if there is 0:0 result in the overall matche summary i don't print it. I've tried everything but nothing worked. Could someone help me?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

Removing the 0 : 0 results of soccer matches to extract the list of results of soccer matches using Selenium Python you need to induce WebDriverWait for the visibility_of_all_elements_located() and you can use either of the following Locator Strategies:

  • Code Block:

    driver.get("https://www.flashscore.com/match/Qs85KCdA/#h2h/overall")
    results = [my_elem.text for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//span[@class='h2h__regularTimeResult' and not(text()='0 : 0')]")))]
    dates = [my_elem.text for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//span[@class='h2h__regularTimeResult' and not(text()='0 : 0')]//ancestor::div[1]/span[@class='h2h__date']")))]
    for i,j in zip(results, dates):
        print(f"{i} result was on {j}")
    driver.quit()
    
  • Console Output:

    1 : 2 result was on 04.12.21
    0 : 2 result was on 01.12.21
    3 : 1 result was on 23.11.21
    1 : 2 result was on 06.12.21
    0 : 5 result was on 01.12.21
    1 : 2 result was on 27.11.21
    1 : 1 result was on 20.11.21
    5 : 1 result was on 30.06.20
    2 : 2 result was on 15.12.19
    1 : 0 result was on 16.04.13
    1 : 1 result was on 18.11.12
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352