【问题标题】:How to get links from table如何从表中获取链接
【发布时间】:2020-08-25 05:53:59
【问题描述】:

我只想从this page 中抓取“下一个匹配项”表中的网址

我用这段代码抓取了所有的网址:

driver.find_elements_by_xpath("//a[@class='in-match']")

我试过这样修改

driver.find_elements_by_xpath("//table[starts-with(@class, 'table-main')]/a[@class='in-match']")

但它不起作用。

【问题讨论】:

  • 欢迎来到 StackOverflow!不幸的是,我现在无法访问该网站,但如果您可以提供屏幕截图或您正在查看的表格 html 的一部分,那么我可能会提供帮助。
  • 您是否缺少//a[@class='in-match'] 以使其变为driver.find_elements_by_xpath("//table[starts-with(@class, 'table-main')]//a[@class='in-match']")?您可以在这里查看类似的问题:sqa.stackexchange.com/questions/34603/…

标签: python selenium selenium-webdriver xpath web-scraping


【解决方案1】:
table/a

表示您要定位 anchor 节点,它是 table 节点的直接子节点。虽然您需要定位 anchor 节点,它是 table 节点的后代

试试

driver.find_elements_by_xpath("//table[starts-with(@class, 'table-main')]//a[@class='in-match']")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    相关资源
    最近更新 更多