【问题标题】:Extract href in table with importxml in Google spreadsheet在 Google 电子表格中使用 importxml 提取表中的 href
【发布时间】:2014-05-21 00:26:49
【问题描述】:

我正在尝试从该网站提取每个表的每一行的 href:

http://www.epa.gov/region4/superfund/sites/sites.html#KY

我可以使用=IMPORTHTML(A1,"table",1) 提取所有 7 个表的表信息,但我需要带有详细信息的站点的href

使用=IMPORTxml(A1,"//div[@class='box']"),我可以从以下网站获取所需信息:

http://www.epa.gov/region4/superfund/sites/fedfacs/alarmyaplal.html

但我需要为原始页面上的每一行提取fedfacs/alarmyaplal.html 部分。

我尝试过使用//@href,但它没有返回任何结果。我在想这是因为数据是在表格中结构化的,但我不知道从哪里开始。

【问题讨论】:

    标签: xpath google-sheets


    【解决方案1】:

    我不确定 Google 电子表格的任何功能,但这里有一个 XPath 可以选择肯塔基州网站的所有 href 属性(因为您的第一个链接包含“ky”锚点):

    //body//a[@id='ky']/following-sibling::table[1]/tbody/tr/td[1]/strong/a/@href
    

    这对 Kentucky 表非常特殊:following-sibling::table[1] 表示在 a[@id='ky'] 之后且处于同一级别的第一个 table 节点。

    【讨论】:

    • 谢谢。我对其进行了更多研究,我的代码在某些 Google 电子表格中有效,而在其他表格中无效。如果我将相同的代码复制到旧工作表中,它可以正常工作。新版 Google 表格似乎有问题。
    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多