remove only some html tags on c#

后端 未结 5 2170
猫巷女王i
猫巷女王i 2021-01-03 09:06

I have a string:

string hmtl = "
xpto

and need to remove the tags of

5条回答
  •  借酒劲吻你
    2021-01-03 09:51

    Use htmlagilitypack

    HtmlDocument doc = new HtmlDocument();
    doc.LoadHtml("yourHtml");
    
    foreach(var item in doc.DocumentNode.SelectNodes("//div"))// "//div" is a xpath which means select div nodes that are anywhere in the html
    {
     item.InnerHtml;//your div content
    }
    

    If you want only B tags..

    foreach(var item in doc.DocumentNode.SelectNodes("//B"))
        {
         item.OuterHtml;//your B tag and its content
        }
    

提交回复
热议问题