Skip to content Skip to sidebar Skip to footer

Can't Figure How To Parse Using Html Agility Pack

I have the following chunk of HTML code but i cant figure how i can get the designated values

Solution 1:

var doc = newHtmlDocument();
doc.Load(url);

var table = doc.DocumentNode.SelectSingleNode("//table[@class='tableclass']");
var value1 = table.Descendants("tr").Skip(1)
    .Select(tr => tr.InnerText.Trim())
    .First();
var theRest =
    from tr in table.Descendants("tr").Skip(2)
    let values = tr.Elements("td")
        .Select(td => td.InnerText.Trim())
        .ToList()
    select new
    {
        Value2 = values[0],
        Value3 = values[1],
        Value4 = values[2],
        Value5 = values[3],
        Value6 = values[4],
    };

Solution 2:

The following...

vardocument = newHtmlDocument();
...

var nodes = document.DocumentNode.Descendants("td");
foreach(var node in nodes)
{
    Console.WriteLine(node.InnerText);
}

Produces...

value1
value2
value3
value4
value5
value6
value2
value3
value4
value5
value6
value2
value3
value4
value5
value6

Hopefully that is what you are after.

Post a Comment for "Can't Figure How To Parse Using Html Agility Pack"