六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

教你一次下載頁面中的所有資源

[摘要]看過一篇關于下載網頁中圖片的文章,它只能下載以http頭的圖片,我做了些改進,可以下載網頁中的所有連接資源,并按照網頁中的目錄結構建立本地目錄,存放資源。download.asp?url=你要下載的網頁download.asp代碼如下 <%Server.ScriptTimeout=9999f...

   看過一篇關于下載網頁中圖片的文章,它只能下載以http頭的圖片,我做了些改進,可以下載網頁中的所有連接資源,并按照網頁中的目錄結構建立本地目錄,存放資源。
download.asp?url=你要下載的網頁

download.asp代碼如下

 <%
Server.ScriptTimeout=9999
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)'中文文件名轉換
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
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 
 
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 


 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 


Function CreateDIR(ByVal LocalPath) '建立目錄的程序,如果有多級目錄,則一級一級的創建
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

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><br>"
SaveToFile getRet,temp&filename
end if
Next
set Matches=nothing
end if
%>
 




主站蜘蛛池模板: 一本一道波多野结衣一区二区 | 婷婷亚洲综合五月天小说 | 伊人久久婷婷丁香六月综合基地 | 一二三四视频免费观看影视 | 亚洲第一天堂无码专区 | 日韩色在线观看 | 欧美一级高清片在线 | 婷婷成人丁香五月综合激情 | 亚洲免费在线观看 | 午夜精品视频5000 | 日韩在线a视频免费播放 | 中文字幕在线免费观看视频 | 青青久视频 | 午夜在线播放视频 | 亚洲中字在线 | 一级女人毛片人一女人 | 欧美一级在线免费观看 | 日韩邪恶 | 伊人久久免费视频 | 人人插人人爽 | 日韩欧美极品 | 五月丁六月停停 | 中文字幕欧美日韩 | 欧美在线区 | 日本天堂在线视频 | 日韩不卡一二三区 | 视频一区二区在线观看 | 青青青草影院 | 日本综合欧美一区二区三区 | 日韩毛片大全免费高清 | 中文字幕日韩一区二区不卡 | 奇米狠狠色 | 亚洲成a人片在线观看中文 亚洲成a人片在线观看精品 | 午夜老司机福利 | 性欧美大战久久久久久久 | 日日夜夜天天操 | 欧美在线看欧美高清视频免费 | 欧美一级视频在线高清观看 | 综合精品 | 日日摸人人拍人人澡 | 亚洲永久视频 |