strs=trim(str) Set Matches =objRegExp.Execute(strs)'开始执行配置 For Each Match in Matches RetStr = RetStr &getimgs( Match.Value )'执行第二轮的匹配 Next ShowPic = RetStr End Function
Function getimgs(str) getimgs="" Set objRegExp1 = New Regexp objRegExp1.IgnoreCase = True objRegExp1.Global = True objRegExp1.Pattern = "http://.+?"""'取出里面的地址 set mm=objRegExp1.Execute(str) For Each Match1 in mm getimgs=getimgs&left(Match1.Value,len(Match1.Value)-1)&"||"'把里面的地址串起来备用 next End Function
'取得图片内容 function getHTTPPage(url) on error resume next dim http set http=server.createobject("MSXML2.XMLHTTP")'使用xmlhttp的方法来获得图片的内容
Http.open "GET",url,false Http.send() if Http.readystate<>4 then exit function end if getHTTPPage=Http.responseBody set http=nothing if err.number<>0 then err.Clear end function
'保存图片 function saveimage(from,tofile) dim geturl,objStream,imgs geturl=trim(from) imgs=gethttppage(geturl)'取得图片的具休内容的过程 Set objStream = Server.CreateObject("ADODB.Stream")'建立ADODB.Stream对象,必须要ADO 2.5以上版本 objStream.Type =1'以二进制模式打开 objStream.Open objstream.write imgs'将字符串内容写入缓冲 objstream.SaveToFile server.mappath(tofile),2'-将缓冲的内容写入文件 objstream.Close()'关闭对象 set objstream=nothing end function
'调用实例 Dim strpic,i,fname strpic = ShowPic("<DIV align=center><IMG src=""http://img.knowsky.com/img/knowskylogo.gif"" border=0></DIV>") strpic = Split(strpic,"||") If UBound(strpic) > 0 Then For i = 0 To UBound(strpic) - 1 '保存图片 fname=cstr(i&mid(strpic(i),instrrev(strpic(i),"."))) saveimage(strpic(i),fname) Next Else End If