【问题标题】:Finding elements that don't have an attribute查找没有属性的元素
【发布时间】:2014-05-07 18:43:52
【问题描述】:

我无法找到返回不具有ID 属性的UL 列表的语法。

以下将返回 Nothing

For Each ul As HtmlAgilityPack.HtmlNode In doc.DocumentNode.SelectNodes("//ul[@id='']")

我知道可以返回所有 UL,然后使用 If 语句单独返回,但是 HtmlAgilityPack 有没有办法返回没有 ID 属性的 UL 列表?

【问题讨论】:

    标签: vb.net xpath html-agility-pack


    【解决方案1】:

    //ul[not(@id)] 可以解决问题。

    演示(使用xmllint):

    $ xmllint index.html --xpath '//ul[not(@id)]/text()'
    1
    3
    

    其中index.html 包含:

    <div>
        <ul>1</ul>
        <ul id="test">2</ul>
        <ul>3</ul>
    </div>
    

    【讨论】:

      猜你喜欢
      • 2013-07-03
      • 2014-01-15
      • 1970-01-01
      • 2016-06-19
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      相关资源
      最近更新 更多