欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

用asp自動解析網(wǎng)頁中的圖片地址

 更新時間:2006年06月13日 00:00:00   作者:  
一,取得原頁中的圖片的地址。
<%
function PicStr(str)
 Set objRegExp = New Regexp '設(shè)置配置對象
 objRegExp.IgnoreCase = True '忽略大小寫
 objRegExp.Global = True '設(shè)置為全文搜索
 objRegExp.Pattern = "<IMG.+?>" '為了確保能準確地取出圖片地址所以分為兩層配置:首先找到里面的<IMG>標簽,然后再取出里面的圖片地址后面的getimgs函數(shù)就是實現(xiàn)后一個功能的。
 strs=trim(str)
 Set Matches =objRegExp.Execute(strs) '開始執(zhí)行配置
 For Each Match in Matches
 PicStr = PicStr &getimgs( Match.Value ) '執(zhí)行第二輪的匹配
 Next
 '所有的圖片在里面都是這樣的src="http://圖片的地址",所以可以這樣來取得確切的圖片地址
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
%>

二,下載圖片并保存在服務(wù)器上。
<%
function getHTTPPage(url)
  on error resume next
  dim http
  set http=server.createobject("MSXML2.XMLHTTP") '使用xmlhttp的方法來獲得圖片的內(nèi)容
  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
'取得了圖片的內(nèi)容要保存,給人一種感覺是用FSO來作就可以了,但實際上不行,這樣保存程序就會出錯,因為FSO不支持流式的文件,所以我們要調(diào)用另一個對象:ADO.STREM。具體的過程如下:
function saveimage(from,tofile)
  dim geturl,objStream,imgs
  geturl=trim(from)
  imgs=gethttppage(geturl)'取得圖片的具休內(nèi)容的過程
  Set objStream = Server.CreateObject("ADODB.Stream")'建立ADODB.Stream對象,必須要ADO 2.5以上版本
  objStream.Type =1'以二進制模式打開
  objStream.Open
  objstream.write imgs'將字符串內(nèi)容寫入緩沖
  objstream.SaveToFile server.mappath(tofile),2'-將緩沖的內(nèi)容寫入文件
  objstream.Close()'關(guān)閉對象
  set objstream=nothing
end function

'所以只要用一個循環(huán)來把剛才取得的地址中的圖片全部保存下來,具體過程如下:
arrimg=split(PicStr(str),"||") '分割字串,取得里面地址列表
allimg=""
newimg=""
for i=1 to ubound(arrimg)
if arrimg(i)<>"" and instr(allimg,arrimg(i))<1 then '看這個圖片是否已經(jīng)下載過
fname=baseurl&cstr(i&mid(arrimg(i),instrrev(arrimg(i),".")))
saveimage(arrimg(i),fname)‘保存地址的函數(shù),過程見上面
allimg=allimg&"||"&arrimg(i) '把保存下來的圖片的地址串回起來,以確定要替換的地址
newimg=newimg&"||"&fname '把本地的地址串回起來
end if
next
'第三步就是替換原來的地址了。具體的過程就是下面了:
arrnew=split(newimg,"||") '取得原來的圖片地址列表
arrall=split(allimg,"||") '取得已經(jīng)保存下來的圖片的地址列表
for i=1 to ubound(arrnew) '執(zhí)行循環(huán)替換原來的地址
  strs=replace(strs,arrall(i),arrnew(i))
next
%>

相關(guān)文章

最新評論