相關資訊
本類常用軟件
-
福建農村信用社手機銀行客戶端下載下載量:584204
-
Windows優(yōu)化大師下載量:416896
-
90美女秀(視頻聊天軟件)下載量:366961
-
廣西農村信用社手機銀行客戶端下載下載量:365699
-
快播手機版下載量:325855
本文是關于ASP下載網頁內的圖片的實例分享,希望對能給大家?guī)韼椭蛦l(fā)。
<%
Function ReplaceRemoteUrl(sHTML, sSaveFilePath, sFileExt)
'//
'//遠程保存圖片
'/////////////////////////////////////////////////////
'作 用:替換字符串中的遠程文件為本地文件并保存遠程文件
'參 數(shù):
' sHTML : 要替換的字符串
' sSavePath : 保存文件的路徑
' sExt : 執(zhí)行替換的擴展名
Dim s_Content
s_Content = sHTML
'If IsObjInstalled("microsoft.XMLHTTP") = False then
'ReplaceRemoteUrl = s_Content
' Exit Function
' End If
'遠程圖片保存目錄,結尾請不要加“/”
SaveFilePath="/upload"
'遠程圖片保存類型
FileExt="jpg|gif|bmp|png"
Dim re, RemoteFile, RemoteFileurl,SaveFileName,SaveFileType,arrSaveFileNameS,arrSaveFileName,sSaveFilePaths
Set re = new RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern = "((http|https|ftp|rtsp|mms):(\/\/|\\\\){1}((\w)+[.]){1,}(net|com|cn|org|cc|tv|[0-9]{1,3})(\S*\/)((\S)+[.]{1}(" & sFileExt & ")))"
's_Content="http://union.3721.com/v2/images/sicon.gif sfsdf"
response.write s_Content
Set RemoteFile = re.Execute(s_Content)
For Each RemoteFileurl in RemoteFile
SaveFileType = Replace(Replace(RemoteFileurl,"/", "a"), ":", "a")
'arrSaveFileName = Right(SaveFileType,12)
arrSaveFileName = Mid(RemoteFileurl,InStrRev(RemoteFileurl, "/")+1)
sSaveFilePaths=sSaveFilePath & "/"
SaveFileName = sSaveFilePaths & arrSaveFileName
Call SaveRemoteFile(SaveFileName, RemoteFileurl)
s_Content = Replace(s_Content,RemoteFileurl,SaveFileName)
Next
ReplaceRemoteUrl = s_Content
End Function
Sub SaveRemoteFile(LocalFileName,RemoteFileUrl)
Dim Ads, Retrieval, GetRemoteData
On Error Resume Next
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set Ads = Server.CreateObject("Adodb.Stream")
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile Server.MapPath(LocalFileName), 2
.Cancel()
.Close()
End With
Set Ads=nothing
End Sub
Server.ScriptTimeOut=6000 '頁面超時時間
url="http://www.webjx.com/htmldata/2006-02-20/1140402873.html"'接收的網址
code=replace(getHTTPPage(url),vbcrlf,"")'替換掉代碼中的 回車符
start=Instr(code,"<html>")'開始的代碼 這里取網頁中有唯一性質的 代碼開始
over=Instr(code,"</html>")'結束的代碼 這里取網頁中有唯一性質的 代碼結束
types=mid(code,start,over-start) 'types 變量就是你需要的部分
'//這里應該繼續(xù)對取得后的代碼做休整 以便符合自己需要
'//我才取的是從<html>到</html> 所以是讀整個頁面 實際上根據(jù)自己需要查看人家的代碼 對照下
'//實際上還需要一些其他的函數(shù) 比如整理HTML標志符的函數(shù), 自動接收遠程圖片的函數(shù)
'//還有就是頁面的自動跳轉等 == 這個就看自己的擴展了
types=ReplaceRemoteUrl(types,SaveFilePath,FileExt)//下載遠程圖片
response.write types ' 測試輸出
'下邊的函數(shù)不用管, 包括 打開,讀取,網頁
Function getHTTPPage(Path)
t = GetBody(Path)
getHTTPPage=BytesToBstr(t,"GB2312")
End function
Function GetBody(url)
on error resume next
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
GetBody = .ResponseBody
End With
Set Retrieval = Nothing
End Function
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
%>