当前位置: 首页 > 图文教程 > 网络编程 > ASP > 教你一次下载网页中的所有资源

ASP
ASP正则表达式技巧
ASP Access实现网站计数器(访问量)
ASP新闻分页,将一篇过长的文章分页,生成静态页面
一些关于asp 购物车的想法
一个sql查询器,自动画表格填字段
ASP实现文件直接下载的代码
把网页中的(电话,qq等数字)生成图片的ASP程序
asp长文章用分页符来分页显示
Asp函数介紹(37个常用函数)
ASP中的面向对象类
分页实现方法的性能比较
asp ajax跨域提交数据
asp修改文件和文件夹的名字的代码
ASP 多关键词查询实例代码
asp被杀毒软件误删的解决方法
asp 多关键词搜索的简单实现方法
asp 根据IP地址自动判断转向分站的代码
asp dictionary对象的用法
ASP 千万级数据分页的存储过程
ASP隐藏真实文件的下载功能实现代码

ASP 中的 教你一次下载网页中的所有资源


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 64 ::
收藏到网摘: n/a

       看过一篇关于下载网页中图片的文章,它只能下载以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
 &nbs