如何使用linq排除特定的HtmlAgility ChildNodes

时间:2013-09-25 21:15:47

标签: .net linq html-agility-pack

我正在尝试解析HTMLNode的所有子节点,其中子节点不是使用HtmlAgility在vb.net中隐藏的输入。

使用以下代码:

    If node.InnerHtml.Length > 10000 Then
                'Parse the current node's child nodes
                For Each child As HtmlNode In node.ChildNodes _
                                                  .Where(Function(c) c.NodeType <> HtmlNodeType.Text _
                                                             AndAlso c.NodeType <> HtmlNodeType.Comment _
                                                             AndAlso c.Name <> "script" _
                                                             AndAlso c.GetAttributeValue("type", "no").ToString() IsNot "hidden")
                    RecursiveHtmlParse(child)
                Next
End If

不幸的是,仍在解析隐藏的输入子节点。我已经尝试了好几个小时,只是不能让foreach跳过它们。

非常感谢任何帮助。

提前致谢!!

1 个答案:

答案 0 :(得分:1)

VB.NET中的IsIsNot运算符检查引用相等性。包含相同值的两个字符串实际上可能引用内存中的不同对象。

请改为尝试:

AndAlso c.GetAttributeValue("type", "no") <> "hidden"

或者这个

AndAlso Not c.GetAttributeValue("type", "no").Equals("hidden")