【问题标题】:How to use SelectNodes method in the case of not before a specific tag在特定标签之前没有的情况下如何使用 SelectNodes 方法
【发布时间】:2014-11-19 21:20:52
【问题描述】:

我的 html 代码很草率,所以我想获取所有具有 class="abcd" 的节点,但此标记不应出现在 class="qwe" 之后。如何在 HTMLAgilityPack.dll 中实现它? 例如,这是我的 html 示例:

           <div class="qwe">
              <div class="abcd">
               ....other tags
              </div>
           </div>
              <div class="abcd">
               ....other tags
              </div>
              <div class="abcd">
               ....other tags
              </div>

所以 SelectNodes 方法应该只返回最后两个标签,而不是第一个。

【问题讨论】:

  • 有什么想法吗????或评论??

标签: html xml xpath html-agility-pack


【解决方案1】:

doc.DocumentNode.SelectNodes(@"//div[@class='abcd' and not(ancestor::*[@class='qwe'])]")

【讨论】:

    猜你喜欢
    • 2018-07-20
    • 2014-09-24
    • 2020-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    相关资源
    最近更新 更多