How to get the contents of a HTML element using HtmlAgilityPack in C#?

后端 未结 2 864
轻奢々
轻奢々 2021-01-18 18:58

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

2条回答
  •  悲&欢浪女
    2021-01-18 19:08

    The following code worked for me

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

提交回复
热议问题