1

I have been trying to work out how to scrape the live and updating statistics on Tennis 24 "https://www.tennis24.com/match/4xFaW6fP/#match-statistics;0" a page such as this but when I try to use selenium nothing is returned. even if I just try to return the 1 element such as

<div class="statText statText--awayValue">4</div>

Could someone please give me some pointers as this is my first scraping project?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Blind Blake
  • 51
  • 10

1 Answers1

1

To print the text 4 you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using XPATH and text attribute:

    driver.get('https://www.tennis24.com/match/4xFaW6fP/#match-statistics;0')
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='statText statText--titleValue' and text()='Aces']//following::div"))).text)
    
  • Using XPATH and get_attribute('innerHTML'):

    driver.get('https://www.tennis24.com/match/4xFaW6fP/#match-statistics;0')
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='statText statText--titleValue' and text()='Aces']//following::div"))).get_attribute('innerHTML'))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you so much for your speedy reply, I will have a go at that today and let you know how it goes. – Blind Blake Sep 10 '20 at 05:30
  • thats brilliant thanks, really appreciated so how would I get all values in that table is it a case of getting all elements? – Blind Blake Sep 10 '20 at 09:02
  • @BlindBlake That sounds to be a different requirement all together. Can you raise a new question with your new requirement please? – undetected Selenium Sep 10 '20 at 09:07
  • I have tried getting the numbers for player A by changing the "following::div" to Before::div) but its not working. am I completely off the mark here? – Blind Blake Sep 10 '20 at 21:46
  • @BlindBlake Feel free to visit [Selenium Chat Room](https://chat.stackoverflow.com/rooms/223360/selenium) and help other users. – undetected Selenium Oct 20 '20 at 18:32