LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

ASP正则判断取出HTML的图片地址、显示、保存等操作的函数

admin
2011年2月15日 23:38 本文热度 2565
用ASP取出HTML里面的图片地址的函数主要原理就是用jsp判断的属性。这在采集程序中将非常有用。函数如下:
 
'显示图片
Function ShowPic(str)
 Set objRegExp = New Regexp'设置配置对象
 objRegExp.IgnoreCase = True'忽略大小写
 objRegExp.Global = True'设置为全文搜索
 objRegExp.Pattern = "<img.+?>"
 '为了确保能准确地取出图片地址所以分为两层配置:首先找到里面的<img>标签,然后再取出里面的图片地址后面的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("<DIV align=center><IMG src=""图片地址"" 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

该文章在 2011/2/15 23:38:47 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved