HtmlAgilityPack DocumentNode.SelectNodes返回null,不应该 [英] HtmlAgilityPack DocumentNode.SelectNodes returns null, shouldn't
问题描述
我试图刮去使用HTML敏捷包一个例子页面内容。当我觉得应该不是DocumentNode.SelectNodes是返回null的XPath查询。有人能告诉我为什么?在code是:
的HTMLDocument DOC =新的HTMLDocument();
字符串的XPath =// H1 [@类='产品称号FN']; //注意,它仍然回报
//即使空// DIV
doc.OptionFixNestedTags = TRUE;
HtmlNode.ElementsFlags.Remove(形式);
HtmlNode.ElementsFlags.Remove(选项);HtmlNodeCollection科尔= doc.DocumentNode.SelectNodes(XPath的);如果(科尔!= NULL)
{
// 做东西
}
其他
{
//没想到它为空,除非没有匹配
}
据上游的bug评论它是一致性:
DarthObiwan写了2011年1月11日在下午9点27分
此之前已经覆盖,这个功能将被写入模仿了System.XML的工作方式。这样做将导致一个重大的重大更改,因此可能会被提名为2.0
块引用>
- 的http://htmlagilitypack.$c$cplex.com/workitem/29175
- 的http://htmlagilitypack.$c$cplex.com/workitem/25973
I'm trying to scrape content from an example page using the HTML agility pack. The DocumentNode.SelectNodes is returning null for an XPath query when I think it shouldn't. Could someone tell me why? The code is:
HtmlDocument doc = new HtmlDocument(); string xpath = "//h1[@class='product-title fn']"; // note, it still returns // null even with "//div" doc.OptionFixNestedTags = true; HtmlNode.ElementsFlags.Remove("form"); HtmlNode.ElementsFlags.Remove("option"); HtmlNodeCollection coll = doc.DocumentNode.SelectNodes(xpath); if (coll != null) { // do stuff } else { // not expecting it to be null unless no matches }
解决方案According to the upstream bug comments it is for consistency:
DarthObiwan wrote Jan 11 2011 at 9:27 PM
This has been covered before, this function is written to mimic the way the System.XML works. Doing so will cause a major breaking change and thus will probably be slated for 2.0
- http://htmlagilitypack.codeplex.com/workitem/29175
- http://htmlagilitypack.codeplex.com/workitem/25973
这篇关于HtmlAgilityPack DocumentNode.SelectNodes返回null,不应该的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!