HtmlAgilityPack DocumentNode.SelectNodes返回null,不应该 [英] HtmlAgilityPack DocumentNode.SelectNodes returns null, shouldn't

查看:1646
本文介绍了HtmlAgilityPack DocumentNode.SelectNodes返回null,不应该的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图刮去使用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


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

这篇关于HtmlAgilityPack DocumentNode.SelectNodes返回null,不应该的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆