网络抓取田纳西州24播放统计

2024-06-26 00:08:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在努力研究如何获取网球24小时直播和更新的统计数据。”https://www.tennis24.com/match/4xFaW6fP/#match-统计信息;0“这样的页面,但当我尝试使用selenium时,不会返回任何内容。即使我只是尝试返回1元素,例如

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

有人能给我一些指点吗,因为这是我的第一个刮削项目


Tags: httpsdivcom信息元素内容wwwmatch
1条回答
网友
1楼 · 发布于 2024-06-26 00:08:45

要打印文本4,需要为visibility_of_element_located()导出WebDriverWait,并且可以使用以下Locator Strategies之一:

  • 使用XPATH文本属性:

    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)
    
  • 使用XPATHget_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'))
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

相关问题 更多 >