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