使用seleniumpython进行web抓取

使用seleniumpython进行web抓取,python,selenium,selenium-webdriver,xpath,web-scraping,Python,Selenium,Selenium Webdriver,Xpath,Web Scraping,我会在这一页上勉强获得开头的赔率 我尝试了以下代码: try: driver.find_element_by_xpath("//td[a[.='bet365']]/following-sibling::td[span]") except NoSuchElementException: homeodd = 'no bet365 odd' drawodd = 'no bet365 odd' awayod

我会在这一页上勉强获得开头的赔率 我尝试了以下代码:

   try:
        driver.find_element_by_xpath("//td[a[.='bet365']]/following-sibling::td[span]")
    except NoSuchElementException:
        homeodd = 'no bet365 odd'
        drawodd = 'no bet365 odd'
        awayodd = 'no bet365 odd'
    else:
        driver.find_element_by_xpath("//*[@id='sortable-1']/tbody/tr[6]/td[4]").click()
        sleep(3)
        homeodd = driver.find_element_by_xpath("//table[ends-with(@id,'16')]//tr[th='Opening odds']/following-sibling::tr/td[@class='bold']").text
        print(homeodd)
        driver.find_element_by_xpath("//*[@id='sortable-1']/tbody/tr[6]/td[5]").click()
        sleep(3)
        drawodd = driver.find_element_by_xpath("//table[ends-with(@id,'16')]//tr[th='Opening odds']/following-sibling::tr/td[@class='bold']").text
        print(drawodd)
        driver.find_element_by_xpath("//*[@id='sortable-1']/tbody/tr[6]/td[6]").click()
        sleep(3)
        awayodd = driver.find_element_by_xpath("//table[ends-with(@id,'16')]//tr[th='Opening odds']/following-sibling::tr/td[@class='bold']").text
        print(awayodd)
我有以下错误:SyntaxError:未能对“文档”执行“evaluate”:字符串“//table[以(@id,'16')结尾]//tr[th='Opening-docks']/following sibling::tr/td[@class='bold']]不是有效的XPath表达式。 然而,我错了xpath语法

问题在于此页面中没有属性
数据打开奇数
。我在上一篇帖子中询问了另一个问题,在社区的大力推荐下,我找到了这个很好的解决方案

try:
        driver.find_element_by_xpath("//td[a[.='bet365']]/following-sibling::td[span]")
    except NoSuchElementException:
        homeodd = 'no bet365 odd'
        drawodd = 'no bet365 odd'
        awayodd = 'no bet365 odd'
    else:
        homeodd = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//td[a[.="bet365"]]/following-sibling::td[span][1]'))).get_attribute("data-opening-odd")
        drawodd = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//td[a[.="bet365"]]/following-sibling::td[span][2]'))).get_attribute("data-opening-odd")
        awayodd = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//td[a[.="bet365"]]/following-sibling::td[span][3]'))).get_attribute("data-opening-odd")
    


有没有建议在不从属性
数据打开奇数
中获得赔率的情况下调整第二个解决方案?谢谢

一个简单的解决方案是使用名为Parse Hub的软件:

您可以刮取使用它的任何网站的数据!如果你在使用它时需要任何帮助的话,它真的很容易使用。告诉我,我会帮你的,但我认为一个YouTube教程可能就足够学习如何使用它了