HTML Agility Pack SelectSingleNode method not listed on Universal Apps (C#)

c# html-agility-pack

Question

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.

1
4
8/30/2015 6:24:33 PM

Accepted Answer

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

5
8/30/2015 5:42:08 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow