最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP编写下载网页中所有资源的程序

日期:10-25    来源:网页设计秀    作者:cnwebshow.com

  看过一篇关于下载网页中图片的文章,它只能下载以http头的图片,我做了些改进,可以下载网页中的所有连接资源,并按照网页中的目录结构建立本地目录,存放资源。Dwp中国设计秀

  download.asp?url=你要下载的网页Dwp中国设计秀

  download.asp代码如下:Dwp中国设计秀

<%Dwp中国设计秀
Server.ScriptTimeout=9999Dwp中国设计秀
function SaveToFile(from,tofile) Dwp中国设计秀
on error resume nextDwp中国设计秀
dim geturl,objStream,imgs Dwp中国设计秀
geturl=trim(from) Dwp中国设计秀
Mybyval=getHTTPstr(geturl) Dwp中国设计秀
Set objStream = Server.CreateObject("ADODB.Stream") Dwp中国设计秀
objStream.Type =1 Dwp中国设计秀
objStream.Open Dwp中国设计秀
objstream.write MybyvalDwp中国设计秀
objstream.SaveToFile tofile,2 Dwp中国设计秀
objstream.Close() Dwp中国设计秀
set objstream=nothing Dwp中国设计秀
if err.number<>0 then err.Clear Dwp中国设计秀
end functionDwp中国设计秀

function geturlencodel(byval url)'中文文件名转换 Dwp中国设计秀
Dim i,code Dwp中国设计秀
geturlencodel="" Dwp中国设计秀
if trim(Url)="" then exit function Dwp中国设计秀
for i=1 to len(Url) Dwp中国设计秀
code=Asc(mid(Url,i,1)) Dwp中国设计秀
if code<0 Then code = code + 65536 Dwp中国设计秀
If code>255 Then Dwp中国设计秀
geturlencodel=geturlencodel&"%"&Left(Hex(Code),2)&"%"&Right(Hex(Code),2) Dwp中国设计秀
else Dwp中国设计秀
geturlencodel=geturlencodel&mid(Url,i,1) Dwp中国设计秀
end if Dwp中国设计秀
next Dwp中国设计秀
end function Dwp中国设计秀
function getHTTPPage(url) Dwp中国设计秀
on error resume next Dwp中国设计秀
dim http Dwp中国设计秀
set http=Server.createobject("Msxml2.xmlhttp") Dwp中国设计秀
Http.open "GET",url,false Dwp中国设计秀
Http.send() Dwp中国设计秀
if Http.readystate<>4 then exit function Dwp中国设计秀
getHTTPPage=bytes2BSTR(Http.responseBody) Dwp中国设计秀
set http=nothing Dwp中国设计秀
if err.number<>0 then err.Clear Dwp中国设计秀
end functionDwp中国设计秀

Function bytes2BSTR(vIn) Dwp中国设计秀
dim strReturn Dwp中国设计秀
dim i,ThisCharCode,NextCharCode Dwp中国设计秀
strReturn = "" Dwp中国设计秀
For i = 1 To LenB(vIn) Dwp中国设计秀
ThisCharCode = AscB(MidB(vIn,i,1)) Dwp中国设计秀
If ThisCharCode < &H80 Then Dwp中国设计秀
strReturn = strReturn & Chr(ThisCharCode) Dwp中国设计秀
Else Dwp中国设计秀
NextCharCode = AscB(MidB(vIn,i+1,1)) Dwp中国设计秀
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode)) Dwp中国设计秀
i = i + 1 Dwp中国设计秀
End If Dwp中国设计秀
Next Dwp中国设计秀
bytes2BSTR = strReturn Dwp中国设计秀
End FunctionDwp中国设计秀

function getFileName(byval filename) Dwp中国设计秀
if instr(filename,"/")>0 thenDwp中国设计秀
fileExt_a=split(filename,"/") Dwp中国设计秀
getFileName=lcase(fileExt_a(ubound(fileExt_a))) Dwp中国设计秀
if instr(getFileName,"?")>0 thenDwp中国设计秀
getFileName=left(getFileName,instr(getFileName,"?")-1)Dwp中国设计秀
end ifDwp中国设计秀
elseDwp中国设计秀
getFileName=filenameDwp中国设计秀
end ifDwp中国设计秀
end functionDwp中国设计秀

function getHTTPstr(url) Dwp中国设计秀
on error resume next Dwp中国设计秀
dim http Dwp中国设计秀
set http=server.createobject("MSXML2.XMLHTTP") Dwp中国设计秀
Http.open "GET",url,false Dwp中国设计秀
Http.send() Dwp中国设计秀
if Http.readystate<>4 then exit function Dwp中国设计秀
getHTTPstr=Http.responseBody Dwp中国设计秀
set http=nothing Dwp中国设计秀
if err.number<>0 then err.Clear Dwp中国设计秀
end functionDwp中国设计秀

Dwp中国设计秀
Function CreateDIR(ByVal LocalPath) '建立目录的程序,如果有多级目录,则一级一级的创建 Dwp中国设计秀
 On Error Resume Next Dwp中国设计秀
 LocalPath = Replace(LocalPath, "", "/") Dwp中国设计秀
 Set FileObject = server.CreateObject("Scripting.FileSystemObject") Dwp中国设计秀
 patharr = Split(LocalPath, "/") Dwp中国设计秀
 path_level = UBound(patharr) Dwp中国设计秀
 For I = 0 To path_level Dwp中国设计秀
  If I = 0 Then pathtmp = patharr(0) & "/" Else pathtmp = pathtmp & patharr(I) & "/" Dwp中国设计秀
   cpath = Left(pathtmp, Len(pathtmp) - 1) Dwp中国设计秀
  If Not FileObject.FolderExists(cpath) Then FileObject.CreateFolder cpath Dwp中国设计秀
 Next Dwp中国设计秀
 Set FileObject = Nothing Dwp中国设计秀
 If Err.Number <> 0 Then Dwp中国设计秀
  CreateDIR = False Dwp中国设计秀
  Err.Clear Dwp中国设计秀
 Else Dwp中国设计秀
  CreateDIR = True Dwp中国设计秀
 End If Dwp中国设计秀
End FunctionDwp中国设计秀

function GetfileExt(byval filename) Dwp中国设计秀
 fileExt_a=split(filename,".") Dwp中国设计秀
 GetfileExt=lcase(fileExt_a(ubound(fileExt_a))) Dwp中国设计秀
end functionDwp中国设计秀

function getvirtual(str,path,urlhead)Dwp中国设计秀
 if left(str,7)="http://" thenDwp中国设计秀
  url=strDwp中国设计秀
 elseif left(str,1)="/" thenDwp中国设计秀
  start=instrRev(str,"/")Dwp中国设计秀
  if start=1 thenDwp中国设计秀
   url="/"Dwp中国设计秀
  elseDwp中国设计秀
   url=left(str,start)Dwp中国设计秀
  end ifDwp中国设计秀
  url=urlhead&urlDwp中国设计秀
  elseif left(str,3)="../" thenDwp中国设计秀
  str1=mid(str,inStrRev(str,"../")+2)Dwp中国设计秀
  ar=split(str,"../")Dwp中国设计秀
  lv=ubound(ar)+1Dwp中国设计秀
  ar=split(path,"/")Dwp中国设计秀
  url="/"Dwp中国设计秀
  for i=1 to (ubound(ar)-lv)Dwp中国设计秀
   url=url&ar(i)Dwp中国设计秀
  nextDwp中国设计秀
  url=url&str1Dwp中国设计秀
  url=urlhead&urlDwp中国设计秀
 elseDwp中国设计秀
  url=urlhead&strDwp中国设计秀
 end ifDwp中国设计秀
 getvirtual=urlDwp中国设计秀
end functionDwp中国设计秀
'示例代码Dwp中国设计秀
dim dlpathDwp中国设计秀

virtual="/downweb/"Dwp中国设计秀
truepath=server.MapPath(virtual)Dwp中国设计秀
if request("url")<> "" thenDwp中国设计秀
 url=request("url")Dwp中国设计秀
 fn=getFileName(url)Dwp中国设计秀
 urlhead=left(url,(instr(replace(url,"//",""),"/")+1))Dwp中国设计秀
 urlpath=replace(left(url,instrRev(url,"/")),urlhead,"")Dwp中国设计秀
 strContent = getHTTPPage(url)Dwp中国设计秀
 mystr=strContentDwp中国设计秀
 Set objRegExp = New Regexp Dwp中国设计秀
 objRegExp.IgnoreCase = True Dwp中国设计秀
 objRegExp.Global = True Dwp中国设计秀
 objRegExp.Pattern = "(src|href)=.[^>]+? "Dwp中国设计秀
 Set Matches =objRegExp.Execute(strContent) Dwp中国设计秀
 For Each Match in Matches Dwp中国设计秀
  str=Match.ValueDwp中国设计秀
  str=replace(str,"src=","")Dwp中国设计秀
  str=replace(str,"href=","")Dwp中国设计秀
  str=replace(str,"""","")Dwp中国设计秀
 str=replace(str,"'","")Dwp中国设计秀
filename=GetfileName(str)Dwp中国设计秀
  getRet=getVirtual(str,urlpath,urlhead)Dwp中国设计秀
  temp=Replace(getRet,"//","**")Dwp中国设计秀
  start=instr(temp,"/")Dwp中国设计秀
  endt=instrRev(temp,"/")-start+1Dwp中国设计秀
  if start>0 thenDwp中国设计秀
   repl=virtual&mid(temp,start)&" "Dwp中国设计秀
   'response.Write repl&"<br>"Dwp中国设计秀
   mystr=Replace(mystr,str,repl)Dwp中国设计秀

  dir=mid(temp,start,endt)Dwp中国设计秀
  temp=truepath&Replace(dir,"/","")Dwp中国设计秀
  CreateDir(temp)Dwp中国设计秀
  'response.Write getRet&"||"&temp&filename&"<br><br>"Dwp中国设计秀
  SaveToFile getRet,temp&filenameDwp中国设计秀
 end ifDwp中国设计秀
Next Dwp中国设计秀
set Matches=nothingDwp中国设计秀
end ifDwp中国设计秀

%> Dwp中国设计秀

本文引用地址:/bc/article_46535.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明