zoukankan      html  css  js  c++  java
  • 过滤HTML字符

    #region 删除所有HTML标签
            /// <summary>
            /// 删除所有HTML标签
            /// </summary>
            /// <param name="Htmlstring"></param>
            /// <returns></returns>
            public static string NoHTML(string Htmlstring)
            {
                //删除脚本  
                Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
                //删除HTML  
                Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);

                Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "   ", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);

                Htmlstring.Replace("<", "");
                Htmlstring.Replace(">", "");
                Htmlstring.Replace("\r\n", "");
                Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

                Htmlstring=ClearString.ClearRequest(Htmlstring);    //过滤关键字

                return Htmlstring;
            }
            #endregion

            #region   移除HTML标签
            ///   <summary>  
            ///   移除HTML标签  
            ///   </summary>  
            ///   <param   name="HTMLStr">HTMLStr</param>  
            public static string ParseTags(string HTMLStr)
            {
                HTMLStr = ClearString.ClearRequest(HTMLStr);    //过滤关键字
                return System.Text.RegularExpressions.Regex.Replace(HTMLStr, "<[^>]*>", "");
            }

            #endregion  

  • 相关阅读:
    PyCharm安装及其使用
    web端自动化——Selenium3+python自动化(3.7版本)-chrome67环境搭建
    Unittest单元测试框架
    selenium IDE下载安装(For Chrome and firefox)
    视频上传测试点
    web端自动化——自动化测试准备工作
    selenium3+Python3+sublime text3自动化登录
    Sublime Text3安装及常用插件安装
    web端自动化——selenium3用法详解
    Selenium2+python自动化2.7-火狐44版本环境搭建(转)
  • 原文地址:https://www.cnblogs.com/di305449473/p/1193301.html
Copyright © 2011-2022 走看看