【问题标题】:TypeError: Cannot read property "tbody" from undefinedTypeError:无法从未定义中读取属性“tbody”
【发布时间】:2012-06-16 08:22:41
【问题描述】:

我正在尝试解析谷歌应用程序脚本中的 html,HTML 中元素的 xPath 是:

/html/body/table/tbody/tr/td/table/tbody/tr[1]/td/table/tbody/tr[3]/td/table/tbody/tr/td/table/tbody/tr/td[2]/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[1]/table[2]/tbody/tr[3]/td[8]

如何在脚本中访问它?我尝试了以下方法:

var doc = Xml.parse(responseText, true);
var number = doc.html.body.table.tbody.tr.td
                .table.tbody.tr[1].td.table.tbody
                .tr[3].td.table.tbody.tr.td.table
                .tbody.tr.td[2].table.tbody.tr[2]
                .td.table.tbody.tr[2].td[2].table
                .tbody.tr[2].td[1].table[2].tbody
                .tr[3].td[1];

请帮忙。

【问题讨论】:

    标签: google-app-engine xml-parsing google-apps-script html-parsing


    【解决方案1】:

    看起来它是您将其视为单个链的元素层次结构。 请发布 xml 字符串 responseText 而不是这个“xPath”,以便您和我们更清楚地看到它。还请在 xml 中指定您要获取的元素。

    当你更新你的问题时,我会更新我的答案。

    【讨论】:

    • responseText是一个HTML代码,很长,怎么附上?
    • 好吧,您可以在 pastebin.com 上进行操作,或者仅粘贴相关部分。这个 xml 是否可以公开访问?我的意思是,我可以自己拿来吗?
    • xPath 本身错误,tbody 是由 firefox 添加的。谢谢大家。
    【解决方案2】:

    xPath 本身错误,tbody 是由 firefox 添加的。所以检查IE中的路径。

    【讨论】:

      猜你喜欢
      • 2014-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多