I'm new in C#. I need to pars link from category and subcategory.
I have a category, but when i try to take subcategory i have error:
"Object reference not set to an instance of an object".
My code:
foreach (var link in xpathLinks)
{
okno.Text += link.Attributes["href"].Value + "\n";
string doc2 = HtmlPage.DownloadString("htmlPage" + link.
Attributes["href"].Value);
dokument2.LoadHtml(doc2);
HtmlNodeCollection xpathLinks2 = dokument2.DocumentNode.
SelectNodes("//ul[@class='category-nav']//li//a");
foreach (var Link in xpathLinks2)
{
okno.Text += Link.Attributes["href"].Value + "\n";
}
}
}
I'm usin HtmlAgilityPack. The error is in xpathLinks2.