【问题标题】:Google Sheets XML path returns no dataGoogle 表格 XML 路径不返回任何数据
【发布时间】:2016-01-20 19:03:23
【问题描述】:

在 Google 表格中使用以下内容:

IMPORTXML("http://www.fishingnotes.com/fishing-report/al/Lake-Purdy","//div[1]/div[1]/div[1]/div[2]/span[2]")

我应该会收到结果:

41°(这是什么) 但谷歌却说导入的内容是空的

我做错了什么?

【问题讨论】:

    标签: xml xpath web-scraping google-sheets


    【解决方案1】:

    使用这个:

    =index(IMPORTXML("http://www.fishingnotes.com/fishing-report/al/Lake-
    Purdy","//span[2][@id='atemp']"),1,1)
    

    它将返回 41°

    或者使用

    =IMPORTXML("http://www.fishingnotes.com/fishing-report/al/Lake-
    Purdy","//span[2][@id='atemp']")
    

    返回 41°(这是什么)

    【讨论】:

    • 完美。但是为什么要索引呢?
    • 没有索引,两个单元格在一个单元格中返回 41°,在右侧的单元格中返回(这是什么)。试试上面没有索引的第二个 =importxlm,你会看到这个。索引仅获取第一行和第一列,即 41°。我以为那是你真正想要的。
    【解决方案2】:

    实际上这个 xpath: //tr[3]/td/text() 将是获取度数的最简单方法:

    =IMPORTXML("http://www.fishingnotes.com/fishing-report/al/Lake-Purdy","//tr[3]/td/text()")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多