国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

用C-#過濾HTML代碼的函數

2020-03-24 15:56:03
字體:
來源:轉載
供稿:網友

正好有時間所以用C#寫了一段html' target='_blank'>正則表達式,作用是刪除 Page 里面Code 中的 HTML標簽

文藝網名[www.la240.com/html2017/1/33/],這在做采集信息,消除其中的HTML很有用處。

以下是引用片段:

publicstringcheckStr(stringhtml)

{

System.Text.RegularExpressions.Regexregex1=newSystem.Text.RegularExpressions.Regex(@"<script[sS]+</script*>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regexregex2=newSystem.Text.RegularExpressions.Regex(@"href*=*[sS]*script*:",System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regexregex3=newSystem.Text.RegularExpressions.Regex(@"no[sS]*=",System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regexregex4=newSystem.Text.RegularExpressions.Regex(@"<iframe[sS]+</iframe*>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regexregex5=newSystem.Text.RegularExpressions.Regex(@"<frameset[sS]+</frameset*>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regexregex6=newSystem.Text.RegularExpressions.Regex(@"<img[^>]+>",System.Text.RegularExpressions.RegexOptions.IgnoreCase); 

System.Text.RegularExpressions.Regexregex7=newSystem.Text.RegularExpressions.Regex(@"</p>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regexregex8=newSystem.Text.RegularExpressions.Regex(@"<p>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regexregex9=newSystem.Text.RegularExpressions.Regex(@"<[^>]*>",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=regex9.Replace(html,"");

html=html.Replace("","");

html=html.Replace("</strong>","");

html=html.Replace("<strong>","");

returnhtml;

}

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泸西县| 德惠市| 任丘市| 肥东县| 荔浦县| 铜陵市| 曲松县| 甘谷县| 井研县| 乐东| 贵定县| 万载县| 佛坪县| 香格里拉县| 泰州市| 阜康市| 通州市| 舒城县| 特克斯县| 开阳县| 松滋市| 宁强县| 金湖县| 四会市| 太保市| 环江| 张家港市| 阳城县| 浠水县| 乌拉特中旗| 昔阳县| 静乐县| 天镇县| 屯留县| 克什克腾旗| 合江县| 麻江县| 个旧市| 子长县| 香港| 海伦市|