【问题标题】:Google Spreadsheet importxml timestampGoogle 电子表格 importxml 时间戳
【发布时间】:2012-12-04 18:12:45
【问题描述】:

我已经尝试了 2 个多小时,将时间戳从 zap2it.com 链接导入到我的谷歌电子表格。



这里是链接 我正在尝试从中导入xml。
http://affiliate.zap2it.com/tvlistings/ZCGrid.do?zipcode=78238&lineupId=DISH641:-



这是我正在尝试导入

这是我目前尝试的方法

=importxml("http://affiliate.zap2it.com/tvlistings/ZCGrid.do?aid=dish&pkg=8388608&fromProvider=true&zipcode=78238&x=52&y=18"&B1,"//body//div[3]/div/div/div[3]/div/div")




编辑 我能够改进并获得更好的结果

//body//div[3]/div/div/div[1]//*

但它显示了整个页面的时间戳。不完全是我需要的。

【问题讨论】:

    标签: xpath xml-parsing google-docs google-sheets


    【解决方案1】:

    [第一个复杂性是从取消引用该 URI 返回的数据流实际上不是 XML;它有数千个格式正确的错误(URI 中未转义的 & 符号、脚本中未转义的 & 符号和小于号、一些嵌入的 HTML、一些杂项错误)。但是,由于您没有报告问题,因此我假设在服务器和您的 XPath 表达式之间的某个地方有人正在做一些整理。]

    我认为如果您使用文档中广泛使用的id 和class 属性,您将获得更好的结果。您想要的材料在源代码中看起来像这样(您可以使用任何基于浏览器的调试工具来查找它;我在 Safari 中使用了“Web Inspector”);我已经缩进以使结构更加可见,并修复了 a 元素之一中的一些格式错误(属性-值对之间缺少空格)。

    <div class="zc-tn" id="zc-tn-top">
      <div class="zc-tn-i">
        <a href="ZCGrid.do?fromTimeInMillis=1355781600000" 
           class="zc-tn-l" 
           title="Move the grid three hours earlier"></a>
        <div class="zc-tn-c">
          <span class="zc-tn-z" 
                title="Central Standard Time">CST</span>
          <div class="zc-tn-t">7:00 PM</div>
          <div class="zc-tn-t">7:30 PM</div>
          <div class="zc-tn-t">8:00 PM</div>
          <div class="zc-tn-t">8:30 PM</div>
          <div class="zc-tn-t">9:00 PM</div>
          <div class="zc-tn-t">9:30 PM</div>
        </div>
        <a href="ZCGrid.do?fromTimeInMillis=1355803200000" 
           class="zc-tn-r" 
           title="Advance the grid three hours"></a>
      </div>
    </div>
    

    简单的搜索验证值zc-tn-top 确实是文档中唯一的ID 值。鉴于此,一个简单的 XPath 表达式来检索图像中显示的所有元素(假设 xhtml 绑定到 XHTML 命名空间):

    //xhtml:div[@id='zc-tn-top']//xhtml:div[@class='zc-tn-t']
    

    从您的问题看来,您的 XPath 评估器似乎是命名空间挑战或命名空间遗忘,因此您可能需要将其写为

    //div[@id='zc-tn-top']//div[@class='zc-tn-t']
    

    【讨论】:

    • 非常感谢,我不知道我可以在不调用 body 的情况下直接 id 和 class,再问 1 个问题,为什么我可以在它的末尾添加 //a 以使其在单行中输出的行。谢谢
    • 在其末尾添加“//a”将使 XPath 表达式不匹配具有 class="zc-tn-t" 的 div 元素集,而是匹配内部的 a 元素集它们(在这种情况下是空集)。我不知道如何回答您关于单行和多行的问题,因为我不知道您的意思。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 2014-04-24
    • 1970-01-01
    • 2019-02-03
    • 1970-01-01
    相关资源
    最近更新 更多