我正在嘗試在VS2008/.Net 3.5中使用HTMLAgilityPack。即使我將OptionUseIdAttribute設置爲true,我也會得到這個錯誤,儘管默認情況下它應該是true。HTMLAgilityPack - 您需要將UseIdAttribute屬性設置爲true以啓用此功能
Error Message:
You need to set UseIdAttribute property to true to enable this feature
Stack Trace:
at HtmlAgilityPack.HtmlDocument.GetElementbyId(String id)
我試過版本1.4.6和1.4.0,都沒有工作。
1.4.6版 - Net20/HtmlAgilityPack.dll
版本1.4.0 - Net20/HtmlAgilityPack.dll
這是代碼,
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);
HtmlNode table = doc.GetElementbyId("tblThreads");
這並沒有工作,要麼,
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = new HtmlDocument { OptionUseIdAttribute = true };
doc = web.Load(url);
HtmlNode table = doc.GetElementbyId("tblThreads");
我該如何解決這個問題? 謝謝。
如果你在加載你的'HtmlDocument'後放置了一個斷點,這個文檔是什麼樣的。即它是否正確加載? – Harrison
是的,它看起來很好,在web.Load(url); – user471317
你能指定url嗎? – Harrison