How to clean up poorly formed HTML using HTML Agility Pack

前端 未结 3 629
时光取名叫无心
时光取名叫无心 2021-02-15 13:41

I am attempting to replace this god awful collection of regular expressions that is currently used to clean up blocks of poorly formed HTML and stumbled upon the HTML Agility Pa

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-15 14:33

    You could try using AngleSharp instead.

    var parser = new HtmlParser();
    var document = parser.Parse(html);
    
    using (var writer = new StringWriter())
    {
        document.ToHtml(writer, new PrettyMarkupFormatter());
        return writer.ToString();
    }
    

提交回复
热议问题