Question

In essence, my Windows Phone 8.1 app is meant to download the html file and parse it using LINQ and HtmlAgilityPack-PCL.

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

Next, I'm attempting to get the node from nodes

        HtmlNode node = nodes.FirstOrDefault();

The exeption "Object reference not assigned to an instance of an object" is where I have it at this point. Definitely, the html file has the div that I'm searching for. So what am I doing incorrectly?

1
1
4/17/2015 3:02:13 AM

Accepted Answer

You most likely mean

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

Please feel free to provide your HTML, or the pertinent portion of it, if that doesn't work.

0
4/17/2015 3:27:26 AM


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