C
C#2mo ago
Akex

Object reference not set to an instance of an object.

root is an HtmlNode but when I try to access anything using SelectSingleNode or SelectNodes it will raise this error when trying to access any methods of them.
HtmlDocument doc = new();
doc.LoadHtml($"{url}/page/{page}/");

HtmlNode root = doc.DocumentNode;
Console.WriteLine(root.GetType());
Console.WriteLine(root.SelectSingleNode("//div").GetType());
HtmlDocument doc = new();
doc.LoadHtml($"{url}/page/{page}/");

HtmlNode root = doc.DocumentNode;
Console.WriteLine(root.GetType());
Console.WriteLine(root.SelectSingleNode("//div").GetType());
5 Replies
jcotton42
jcotton422mo ago
Does LoadHtml actually take a URL? I would assume it takes an HTML string.
Akex
Akex2mo ago
it does take an html string... im suprised it did not log anything in console about it being an url ty @jcotton42
jcotton42
jcotton422mo ago
Console logging on errors isn’t a thing .net libraries do. They would throw exceptions.
Akex
Akex2mo ago
im thinking in a python way I get what you mean
jcotton42
jcotton422mo ago
Quality Python libs don’t do that either.
Want results from more Discord servers?
Add your server
More Posts