Skip to content Skip to sidebar Skip to footer

How To Get The Contents Of A Html Element Using Htmlagilitypack In C#?

I want to get the contents of an ordered list from a HTML page using HTMLAgilityPack in C#, i have tried the following code but, this is not working can anyone help, i want to pass

Solution 1:

How about:

var el = (HtmlElement)doc.DocumentNode
    .SelectSingleNode("//ol");
if(el!=null)
{
    string s = el.OuterHtml;
}

(untested, from memory)

Solution 2:

The following code worked for me

publicstaticstringGetComments(string html)
{
    HtmlDocument doc = new HtmlDocument();
    doc.LoadHtml(html);
    string s = "";
    foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//ol"))
    {
        s += node.OuterHtml;
    }

    return s;
}

Post a Comment for "How To Get The Contents Of A Html Element Using Htmlagilitypack In C#?"