I'm trying to get a single node after I locate the htmlnode with a specific tag. But what I get back is an error:
Object reference not set to an instance of an object.
Now here is the code:
HtmlWeb htmlWeb = new HtmlWeb();
// Creates an HtmlDocument object from an URL
HtmlAgilityPack.HtmlDocument document = htmlWeb.Load(url);
// Targets a specific node
// If there is no node with that Id, someNode will be null
HtmlNode someNode = document.GetElementbyId("<li name=\"XU\">");
var parseString = someNode.SelectSingleNode("//span[@class='lp']");
My purpose is to get all the nodes within the XU li tag. I know the name of the classes.
Also just to note that when I'm replacing the last code line with a
var parseString = document.DocumentNode.SelectSingleNode("//span[@class='long-position']");
then the tag argument within the SelectSingleNode is working fine.
HtmlNode someNode = document.SelectSingleNode("//li[@name='XU']").SelectSingleNode("/span[@class='lp']");