设为首页
加入收藏
站点地图
首页 | 网站建设 | 杭州FPGA培训班,浙江FPGA培训班,苏州FPGA培训班,昆山FPGA培训班,常州FPGA培训班优化 | 网站推广 | 网络营销 | 网站运营 | 网站策划 | 在线讨论 | 下载中心
您当前的位置:WebSite -> 网站建设 -> 文章内容正文->ASP取出HTML里面的图片地址的实用函数
 子栏目导航
 热门文章
 相关文章
 

ASP取出HTML里面的图片地址的实用函数

作者:佚名  来源:转载  发布时间:2008-7-15 10:01:18  

以下是取出HTML里面的图片地址的函数:

主要原理就是用正则判断  的属性。这在采集程序中将非常有用。

函数如下:

Function ShowPic(str) 
 Set objRegExp = New Regexp'设置配置对象  
 objRegExp.IgnoreCase = True'忽略大小写  
 objRegExp.Global = True'设置为全文搜索  
 objRegExp.Pattern = "" 
 '为了确保能准确地取出图片地址所以分为两层配置:首先找到里面的标签,然后再取出里面的图片地址后面的getimgs函数就是实现后一个功能的。  
 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("

 

") 
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

 [返回上一页] [打 印] [收 藏]
百度中查看“ASP取出HTML里面的图片地址的实用函数”相关文章

版权申明:本站网站建设资源来源网络,如有侵犯您的版权,请来Q告知 我们会在24小时内删除!

Copyright © 2008-2010 www.mepeixun.com All Rights Reserved
服务QQ:52466268 邮箱:meipeixun@163.com
备案号:苏ICP备07200130号