ASP:小偷例子之保存遠程圖片

 <%
Function ReplaceRemoteUrl(sHTML, sSaveFilePath, sFileExt)
'//
'//遠程保存圖片
'/////////////////////////////////////////////////////
'作 用:替換字符串中的遠程文件爲本地文件並保存遠程文件
'參 數:
'     sHTML        : 要替換的字符串
'     sSavePath    : 保存文件的路徑
'     sExt         : 執行替換的擴展名
    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 & ")))"
    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://gamezone.qq.com/a/20040917/000070.htm"'接收的網址
code=replace(getHTTPPage(url),vbcrlf,"")'替換掉代碼中的 回車符

start=Instr(code,"<html>")'開始的代碼 這裏取網頁中有唯一性質的 代碼開始
over=Instr(code,"</html>")'結束的代碼 這裏取網頁中有唯一性質的 代碼結束
types=mid(code,start,over-start) 'types 變量就是你需要的部分
'//這裏應該繼續對取得後的代碼做休整 以便符合自己需要
'//我才取的是從<html>到</html> 所以是讀整個頁面 實際上根據自己需要查看人家的代碼 對照下
'//實際上還需要一些其他的函數 比如整理HTML標誌符的函數, 自動接收遠程圖片的函數
'//還有就是頁面的自動跳轉等 == 這個就看自己的擴展了
types=ReplaceRemoteUrl(types,SaveFilePath,FileExt)//下載遠程圖片
response.write types ' 測試輸出
'下邊的函數不用管, 包括 打開,讀取,網頁
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
%>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章