• c# 过滤html


      public static string StripHTML(string html)
            {
                try
                {
                    System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[sS]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[sS]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[sS]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[sS]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[sS]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"<img[^>]+>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    
                    html = regex1.Replace(html, ""); //过滤<script></script>标记
                    html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
                    html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on事件
                    html = regex4.Replace(html, ""); //过滤iframe
                    html = regex5.Replace(html, ""); //过滤frameset
                    html = regex6.Replace(html, ""); //过滤frameset
                    html = regex7.Replace(html, ""); //过滤frameset
                    html = regex8.Replace(html, ""); //过滤frameset
                    html = html.Replace(" ", "");
                    html = html.Replace("</strong>", "");
                    html = html.Replace("<strong>", "");
                    html = html.Replace("
    ", "");
                    html = html.Replace("
    ", "");
                    html = html.Replace("'", "");
                    html = html.Replace(""", "");
                    html = html.Replace("	", "");
                    return html;
                }
                catch
                {
                    //MessageBox.Show("Error");
                    return html;
                }
            }
  • 相关阅读:
    【uniapp】改善中大型uniapp小程序项目开发体验
    vite试玩:老项目启动从6分钟到秒开
    修剪AST树减少webapck打包尺寸
    librispeech数据集下载
    语音识别性能评估方法
    2021.12.11 物联网考试
    2021.12.15 课程总结+加分项
    2021.12.9 观影大数据分析
    2021.12.8 Docker服务
    2021.12.10 阿里云服务器创建
  • 原文地址:https://www.cnblogs.com/feizianquan/p/9720751.html
Copyright © 2020-2023  润新知