HtmlAgilityPack and selecting Nodes and Subnodes

前端 未结 5 1351
轻奢々
轻奢々 2021-01-31 02:12

Hope somebody can help me.

Let´s say I have a html document that contains multiple divs like this example:

5条回答
  •  迷失自我
    2021-01-31 03:04

    If you use //, it searches from the document begin.

    Use .// to search all from the current node

     foreach (HtmlAgilityPack.HtmlNode node2 in node.SelectNodes(".//span[@prop]"))
    

    Or drop the prefix entirely to search just for direct children:

     foreach (HtmlAgilityPack.HtmlNode node2 in node.SelectNodes("span[@prop]"))
    

提交回复
热议问题