zoukankan      html  css  js  c++  java
  • 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;
                }
            }
  • 相关阅读:
    记录「十一月做题记录」
    题解「GMOJ6898 【2020.11.27提高组模拟】第二题」
    题解「CFGYM102331B Bitwise Xor」
    题解「Japan Alumni Group Summer Camp 2018 Day 2J AB Sort」
    题解「AGC048B Bracket Score」
    题解「中位数之中位数 median」
    记录「十月做题记录」
    测试「2020牛客NOIP赛前集训营-提高组(第五场)」
    测试「20201028测试总结」
    定时提醒助手
  • 原文地址:https://www.cnblogs.com/feizianquan/p/9720751.html
Copyright © 2011-2022 走看看