First I used ILSpy in 1.4.0 HAP Dll. I went over to the HtmlDocument class and saw that the GetElementById method looks like this:
// HtmlAgilityPack.HtmlDocument /// <summary> /// Gets the HTML node with the specified 'id' attribute value. /// </summary> /// <param name="id">The attribute id to match. May not be null.</param> /// <returns>The HTML node with the matching id or null if not found.</returns> public HtmlNode GetElementbyId(string id) { if (id == null) { throw new ArgumentNullException("id"); } if (this._nodesid == null) { throw new Exception(HtmlDocument.HtmlExceptionUseIdAttributeFalse); } return this._nodesid[id.ToLower()] as HtmlNode; }
Then I got ILSpy to analyze "_nodesid", because in your case, for some reason, it is not installed. "HtmlDocument.DetectEncoding (TextReader)" and "HtmlDocument.Load (TextReader)" assigns the value "_nodesid".
Therefore, you can try an alternative method for reading content from a URL where the value "_nodesid" will definitely be assigned, for example.
var doc = new HtmlDocument(); var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; using (var response = (HttpWebResponse)request.GetResponse()) { using (var stream = response.GetResponseStream()) { doc.Load(stream); } } var table = doc.GetElementbyId("tblThreads");
This approach ensures that "HtmlDocument.Load (TextReader)" is called, and in this code I see that _nodesid will definitely be assigned, so this approach may (I have not compiled the code I proposed) work.
source share