取Img Src值的几种方法

<script language="VBScript">
<!--
Function RemoveHTML(strHTML) 
Dim objRegExp, Match, Matches 
Set objRegExp = New Regexp 

objRegExp.IgnoreCase = True 
objRegExp.Global = True 
'取闭合的<> 
objRegExp.Pattern = "<img src=.+?>" 

Set Matches = objRegExp.Execute(strHTML) 

For Each Match in Matches 
t=t & Match.value
Next 
RemoveHTML=t
Set objRegExp = Nothing 
End Function

a="<br>这是一个IMG函数<img src=""http://www.baidu.com/img/logo-yy.gif"">这是结束位置"
msgbox replace(replace(replace(replace(replace(removehtml(a),"<",""),">",""),"img",""),"""",""),"src=","")

-->
</script>
 
 <script type="text/javascript">
<!--
  var imgurl1="<img src=\"sdf1.gif\" border=0 height=0>sdfds<img src=\"sdf2.gif\" border=0 height=0>sdds<img src=\"sdf3.gif\" border=0 height=0>";
  var reimg=/<img src=(.+?)>/gi;
  if(arr=imgurl1.match(reimg)){
   for(i=0;i<arr.length;i++){
    alert(arr[i].replace(/<img src=([^\s]+)\s*[^>]*>/gi,"$1"));
   }
  } 
-->  
</script> 
 <script language="VBScript">
a="<br>这是一个IMG函数<img width=130 οnclick=""test();"" src=""http://www.baidu.com/img/logo-yy.gif"">这是<img width=130 οnclick=""test();"" src=""http://www.baidu.com/img/logo-yy2.gif"">"
call process_content_photo(a)
'==============================
''处理内容中所有图片
'==============================

Function process_content_photo(strContent)
        Dim objRegEx,MyPics, MyPic
        Set objRegEx = New RegExp
        objRegEx.IgnoreCase = true
        objRegEx.Global = True
        objRegEx.Pattern = "<img[^<>]+?>"
        Set MyPics = objRegEx.Execute(strContent)
        For Each MyPic in MyPics
  document.write(GetAttribute("src", MyPic.Value) & "<br>")
        Next
        Set MyPics = Nothing
        Set objRegEx = Nothing
End Function

 

'==============================
'【功能】取得参数值
'==============================

Function GetAttribute(ByVal strAttribute, ByVal strtag)
        Dim objRegEx, Matches
        '建立正则表达式
        Set objRegEx = New RegExp
        '查找内容
        objRegEx.Pattern = LCase(strAttribute) & "=""([^\[]*)"""
        '忽略大小写
        objRegEx.IgnoreCase = True
        '全局查找
        objRegEx.Global = True
        '执行搜索
        Set Matches = objRegEx.Execute(strtag)
        '如有匹配的则返回值, 不然返回空值
        If Matches.Count > 0 Then
                GetAttribute = Split(Matches(0).Value, """")(1)
        Else
                GetAttribute = ""
        End If
        '消毁对象
        Set Matches = Nothing
        Set objRegEx = Nothing
End Function
</script>
 

转载于:https://www.cnblogs.com/exit/archive/2010/11/10/1874239.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值