Question

Well, basically I have a Windows Phone 8.1 app that's supposed to download the html file and parse it using HtmlAgilityPack-PCL and LINQ.

var nodes = from tr in doc.DocumentNode.Descendants("body")
                from td in tr.Descendants("div").Where(x =>
x.Attributes["id"].Value == "screen")select tr;

Then I'm trying to get the node from nodes:

        HtmlNode node = nodes.FirstOrDefault();

And this is the point where i have an exeption "Object reference not set to an instance of an object." The html file definitely has the div I am looking for. So what am I doing wrong?

Accepted Answer

you probably mean

var node = doc.DocumentNode.Descendants("div").
               Where(div => div.GetAttributeValue("id", string.Empty) == "screen").
               FirstOrDefault();

if that does not work feel free to share your html or the relevant part of it.



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why