打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
从源代码中提取或过滤网页标签

1.删除非图片标签

先把img标签转换成特定字符,再其他的html中 <和> 过滤掉,再把刚才的特定字符转换回来

html   =   html.replace(// <img/g, "♂ ");                   ///替换 " <img "
html   =   html.replace(/(♂[^> ]*)> /g, "$1♀ ");     ///替换 "> "
alert(html);
html   =   html.replace(// <[^> ]*> /g, " ");                 ///过滤其它所有 " <...> "标签
alert(html);
html   =   html.replace(/♂/g, " <img ");                     ///还原 " <img "
html   =   html.replace(/♀/g, "> ");                           ///还原 "> "

 

2.正则表达式过滤图片标签 自己所写

Function RemoveImg(ByVal str As String) As String
    Dim re
    Set re = New RegExp
    re.IgnoreCase = True
    re.Global = True
    re.Pattern = "<img[^>]*>"
    RemoveImg = re.Replace(str, " ")
End Function

 

Function RemoveScript(ByVal str As String) As String '过滤脚本
    Dim re
    Set re = New RegExp
    re.IgnoreCase = True
    re.Global = True
    re.Pattern = "<script[/w/W]*script>"
    RemoveScript = re.Replace(str, " ")
End Function

Function RemoveEmbed(ByVal str As String) As String '过滤嵌入多媒体
    Dim re
    Set re = New RegExp
    re.IgnoreCase = True
    re.Global = True
    re.Pattern = "<embed[/w/W]*embed>"
    RemoveEmbed = re.Replace(str, " ")
End Function

Function RemoveObject(ByVal str As String) As String '过滤嵌入多媒体
    Dim re
    Set re = New RegExp
    re.IgnoreCase = True
    re.Global = True
    re.Pattern = "<object[/w/W]*object>"
    RemoveEmbed = re.Replace(str, " ")
End Function

 

3.字符串遍历过滤图片标签

Private Function RemoveImg(ByVal str As String) As String
    '不显示图片
    Dim i As Integer
    Dim tempSource, tempStr As String
    Dim img() As String
    tempSource = str
    img = Split(str, "<img")
    For i = 1 To UBound(img) - 1
        tempStr = Split(img(i), ">")(0) '<img> 标签的结束
        tempSource = Replace(tempSource, "<img" & tempStr & ">", "", 1, -1, 1)
    Next
    RemoveImg = tempSource
End Function

 

4.操作页面元素

for(i=0;i<document.getElementsByTagName.length;i++){
    document.getElementsByTagName("input")[i].style.background="#CCCCCC";

}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
asp用正则过滤html标签
如何从Html页面中提取所有汉字
用VB读取unicode 编码的中英文字符混合的文本文件,中文显示乱码怎么解决?
141.从字符串提取纯数字
vb RegExp的Test方法
转帖工具(放到首页左栏随时调用)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服