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

ASP
绑定txt文件到DataGrid
在用户离开页面时提示信息
asp + oracle 分页方法(不用存储过程)
asp + sqlserver 分页方法(不用存储过程)
验证身份证号是否正确的代码
检查有日文片假名的新闻
asp关键字函数运算附
ASP中也能解压缩rar文件
ASP文章系统解决方案
DW+ASP 玩转动态二级菜单
在ASP中操作数据库的方法
ASP做象资源管理器的树形目录
在asp中结合对象和组件
Active Server Pages是什么?
ActiveServerPages是怎样工作?
ASP脚本基础
ASP中的内建对象Server
在网页中动态的生成一个gif图片
ASP.NET中的状态管理
解决ASP执行DB查询中的特殊字符问题

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 30 ::
收藏到网摘: 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