I am developing a simple web scraping app in C# and here is my code to load html code received from the server to HtmlDocument
.
string html = res.Content.ToString();
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
Whenever I try to use the htmlDoc.DocumentNode.SelectSingleNode
method I am getting this error:
"Html node does not contain a reference for SelectSingleNode".
Am I missing something?
I am developing a universal app in Visual Studio 2015. Downloaded and installed html agility pack using Nuget manager.
Universal app doesn't support XPath. So you can not use SelectSingleNode or SelectNodes methods. But You can use Linq, like
doc.DocumentNode.Descendants("a")
.Where(a => a.InnerText.Contains("some text"))
.Select(a => a.Attributes["href"].Value);
to get the same nodes