How to use HTML Agility pack

后端 未结 7 1809
闹比i
闹比i 2020-11-21 04:30

How do I use the HTML Agility Pack?

My XHTML document is not completely valid. That\'s why I wanted to use it. How do I use it in my project? My project is in C#.

7条回答
  •  礼貌的吻别
    2020-11-21 05:11

    try this

    string htmlBody = ParseHmlBody(dtViewDetails.Rows[0]["Body"].ToString());
    
    private string ParseHmlBody(string html)
            {
                string body = string.Empty;
                try
                {
                    var htmlDoc = new HtmlDocument();
                    htmlDoc.LoadHtml(html);
                    var htmlBody = htmlDoc.DocumentNode.SelectSingleNode("//body");
                    body = htmlBody.OuterHtml;
                }
                catch (Exception ex)
                {
    
                    dalPendingOrders.LogMessage("Error in ParseHmlBody" + ex.Message);
                }
                return body;
            }
    

提交回复
热议问题