一次性下載遠(yuǎn)程頁面上的所有內(nèi)容
使用方法,將上面的代碼保存為一個(gè)比如:downfile.asp
在瀏覽器上輸入:
http://你的地址/downfile.asp?url=http://www.baidu.com/index.html
<% "設(shè)置超時(shí)的時(shí)間 Server.ScriptTimeout=9999 "############## "文件保存函數(shù) "############# function SaveToFile(from,tofile) on error resume next dim geturl,objStream,imgs geturl=trim(from) Mybyval=getHTTPstr(geturl) Set objStream = Server.CreateObject("ADODB.Stream") objStream.Type =1 objStream.Open objstream.write Mybyval objstream.SaveToFile tofile,2 objstream.Close() set objstream=nothing if err.number<>0 then err.Clear end function "############## "字符處理替換 "############# function geturlencodel(byval url)"中文文件名轉(zhuǎn)換 Dim i,code geturlencodel="" if trim(Url)="" then exit function for i=1 to len(Url) code=Asc(mid(Url,i,1)) if code<0 Then code = code + 65536 If code>255 Then geturlencodel=geturlencodel&"%"&Left(Hex(Code),2)&"%"&Right(Hex(Code),2) else geturlencodel=geturlencodel&mid(Url,i,1) end if next end function "############## "XML獲取遠(yuǎn)程頁面開始 "############# function getHTTPPage(url) on error resume next dim http set http=Server.createobject("Msxml2.XMLHTTP") Http.open "GET",url,false Http.send() if Http.readystate<>4 then exit function getHTTPPage=bytes2BSTR(Http.responseBody) set http=nothing if err.number<>0 then err.Clear end function Function bytes2BSTR(vIn) dim strReturn dim i,ThisCharCode,NextCharCode strReturn = "" For i = 1 To LenB(vIn) ThisCharCode = AscB(MidB(vIn,i,1)) If ThisCharCode < &H80 Then strReturn = strReturn & Chr(ThisCharCode) Else NextCharCode = AscB(MidB(vIn,i+1,1)) strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode)) i = i + 1 End If Next bytes2BSTR = strReturn End Function "############## "XML獲取遠(yuǎn)程頁面結(jié)束,這段是小偷程序都通用的部分 "############# "############## "分解地址,取得文件名 "############# function getFileName(byval filename) if instr(filename,"/")>0 then fileExt_a=split(filename,"/") getFileName=lcase(fileExt_a(ubound(fileExt_a))) if instr(getFileName,"?")>0 then getFileName=left(getFileName,instr(getFileName,"?")-1) end if else getFileName=filename end if end function "############## "獲取遠(yuǎn)程頁面函數(shù) "############# function getHTTPstr(url) on error resume next dim http set http=server.createobject("MSXML2.XMLHTTP") Http.open "GET",url,false Http.send() if Http.readystate<>4 then exit function getHTTPstr=Http.responseBody set http=nothing if err.number<>0 then err.Clear end function "############## "FSO處理函數(shù),創(chuàng)建目錄 "############# Function CreateDIR(ByVal LocalPath) "建立目錄的程序,如果有多級目錄,則一級一級的創(chuàng)建 On Error Resume Next LocalPath = Replace(LocalPath, "", "/") Set FileObject = server.CreateObject("Scripting.FileSystemObject") patharr = Split(LocalPath, "/") path_level = UBound(patharr) For I = 0 To path_level If I = 0 Then pathtmp = patharr(0) & "/" Else pathtmp = pathtmp & patharr(I) & "/" cpath = Left(pathtmp, Len(pathtmp) - 1) If Not FileObject.FolderExists(cpath) Then FileObject.CreateFolder cpath Next Set FileObject = Nothing If Err.Number <> 0 Then CreateDIR = False Err.Clear Else CreateDIR = True End If End Function function GetfileExt(byval filename) fileExt_a=split(filename,".") GetfileExt=lcase(fileExt_a(ubound(fileExt_a))) end function "############## "如何獲取虛擬的路徑 "############# function getvirtual(str,path,urlhead) if left(str,7)="http://" then url=str elseif left(str,1)="/" then start=instrRev(str,"/") if start=1 then url="/" else url=left(str,start) end if url=urlhead&url elseif left(str,3)="../" then str1=mid(str,inStrRev(str,"../")+2) ar=split(str,"../") lv=ubound(ar)+1 ar=split(path,"/") url="/" for i=1 to (ubound(ar)-lv) url=url&ar(i) next url=url&str1 url=urlhead&url else url=urlhead&str end if getvirtual=url end function |
"示例代碼
dim dlpath "建立一個(gè)文件夾,以便存放這些獲取的數(shù)據(jù) virtual="/downweb/" truepath=server.MapPath(virtual) if request("url")<> "" then url=request("url") fn=getFileName(url) urlhead=left(url,(instr(replace(url,"http://",""),"/")+1)) urlpath=replace(left(url,instrRev(url,"/")),urlhead,"") strContent = getHTTPPage(url) mystr=strContent Set objRegExp = New Regexp objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.Pattern = "(src|href)=.[^>]+? " Set Matches =objRegExp.Execute(strContent) For Each Match in Matches str=Match.Value str=replace(str,"src=","") str=replace(str,"href=","") str=replace(str,"""","") str=replace(str,""","") filename=GetfileName(str) getRet=getVirtual(str,urlpath,urlhead) temp=Replace(getRet,"http://","**") start=instr(temp,"/") endt=instrRev(temp,"/")-start+1 if start>0 then repl=virtual&mid(temp,start)&" " "response.Write repl&"<br>" mystr=Replace(mystr,str,repl) dir=mid(temp,start,endt) temp=truepath&Replace(dir,"/","") CreateDir(temp) response.Write getRet&"||"&temp&filename&"<br>" response.Write "成功取得"&filename&"這個(gè)文件<br>" response.Write "并將"&filename&"保存在"&temp&"<br><br>" response.Write "<HR>" SaveToFile getRet,temp&filename end if Next set Matches=nothing end if %> |
聲明:本頁內(nèi)容由湖南景煌網(wǎng)絡(luò)通過網(wǎng)絡(luò)收集編輯所得,所有資料僅供用戶參考;本站不擁有所有權(quán),也不承認(rèn)相關(guān)法律責(zé)任。如您認(rèn)為本網(wǎng)頁中有涉嫌抄寫的內(nèi)容,請及時(shí)與我們聯(lián)系進(jìn)行舉報(bào),并提供相關(guān)證據(jù),工作人員會在5個(gè)工作日內(nèi)聯(lián)系您,一經(jīng)查實(shí),本站將立刻刪除涉嫌侵權(quán)內(nèi)容。如果您對網(wǎng)站優(yōu)化核心技術(shù)文章感興趣,請點(diǎn)擊查看網(wǎng)站建設(shè)和網(wǎng)站推廣的相關(guān)文章,請關(guān)注湖南景煌網(wǎng)絡(luò)官網(wǎng)(www.banjiwang.cn)
全國7x24小時(shí)客服熱線
50倍賠付終端服務(wù)時(shí)間
部分產(chǎn)品可享受15天無理由退款
全國多家分公司便捷服務(wù)
持續(xù)陪伴企業(yè)成長,共創(chuàng),共贏
幫助企業(yè)建設(shè)全網(wǎng)營銷生態(tài)鏈
讓企業(yè)與用戶快速連接一切
為企業(yè)與用戶搭建共享開發(fā)平臺
0731-82272030
公司地址:長沙市雨花區(qū)韶山北路460號(原86號)興威名座北棟1202室
長沙市芙蓉區(qū)、天心區(qū)、岳麓區(qū)、開福區(qū)、雨花區(qū)、望城區(qū)均可提供上門洽談服務(wù)
湖南景煌網(wǎng)絡(luò)科技有限公司--為你提供網(wǎng)站建設(shè)、百度SEO、網(wǎng)站優(yōu)化、網(wǎng)絡(luò)推廣、百度排名、小程序開發(fā)等服務(wù)
微信公眾號