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

ASP
认识和优化connection对象
优化你的ASP程序
ASP实现简单的网页保护
在ASP中限制同一表单被多次提交
Request 对象 属性和方法
asp的Request对象
全角与半角字符的相互转换的asp函数
asp session 使用数组
防止ASP Session丢失的方法
cookies和session的关系
无组件不能上传rar,zip其它非图片文件
网站设计时应注意的SEO细节
asp代码--fso创建文件夹
ASP转化ip地址为长整型数字
关于script的dictionary对象的用法
asp过滤不文明字符的函数
fso删除当前文件夹下所有的内容
asp中将字符转换成变量使用
asp数组随机排序
解决asp被杀毒软件误删的方法

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


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