1
我试图从HTML示例页面中使用HTML敏捷包来抓取内容。当我认为它不应该时,DocumentNode.SelectNodes为XPath查询返回null。有人能告诉我为什么吗?该代码是:HtmlAgilityPack DocumentNode.SelectNodes返回null,不应该
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
}
后页面标记。你知道,我们无法猜测它。 – Oded 2011-12-23 19:03:34
Doh,忘记加载在我的UnitTest中的doc.Load url中,因此错误。如果有人可以删除这个非常感谢的问题。 谢谢,科林。 – 2011-12-23 19:08:15
您可以删除它。在标签下看到那个小小的'delete'链接? – Oded 2011-12-23 19:08:45