【问题标题】:HtmlAgilityPack Multiple Types of DescendantsHtmlAgilityPack 多种后代类型
【发布时间】:2012-12-18 02:34:53
【问题描述】:

我正在尝试选择 div、span、标签等,基本上是任何具有特定属性的元素。

IEnumerable<HtmlNode> allDivsWithItemType = _doc.DocumentNode.Descendants("div").Where(d => d.Attributes.Contains("itemtype"));

有没有办法像上面那样将所有后代都捆绑在一起?由于上面显然只能找到 div。我试图避免重复的代码添加一整行来替换一个单词。

例如(不起作用)

IEnumerable<HtmlNode> allDivsWithItemType = _doc.DocumentNode.Descendants("*").Where(d => d.Attributes.Contains("itemtype"));

【问题讨论】:

    标签: html linq html-agility-pack


    【解决方案1】:

    试试:

    IEnumerable<HtmlNode> allDivsWithItemType = _doc.DocumentNode.Descendants()
       .Where(d => d.Attributes.Contains("itemtype"));
    

    【讨论】:

    • 据我所知,工作就像一个魅力。
    猜你喜欢
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    • 2016-11-13
    • 1970-01-01
    • 2016-09-09
    • 2020-08-03
    • 2019-03-11
    • 1970-01-01
    相关资源
    最近更新 更多