一次性下载远程页面上的所有内容使用方法,将上面的代码保存为一个比如:downfile.asp在浏览器上输入:http://你的地址/downfile.asp?url=http://www.baidu.com/index.html
<%'设置超时的时间Server.ScriptTimeout=9999'##############'文件保存函数'#############function SaveToFile(from,tofile)on error resume nextdim geturl,objStream,imgs geturl=trim(from) Mybyval=getHTTPstr(geturl) Set objStream = Server.CreateObject("ADODB.Stream") objStream.Type =1 objStream.Open objstream.write Mybyvalobjstream.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'##############'XML获取远程页面开始'#############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 '##############'XML获取远程页面结束,这段是小偷程序都通用的部分'#############'##############'分解地址,取得文件名'#############function getFileName(byval filename) if instr(filename,"/")>0 thenfileExt_a=split(filename,"/") getFileName=lcase(fileExt_a(ubound(fileExt_a))) if instr(getFileName,"?")>0 thengetFileName=left(getFileName,instr(getFileName,"?")-1)end ifelsegetFileName=filenameend ifend 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 '##############'FSO处理函数,创建目录'#############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://" thenurl=strelseif left(str,1)="/" thenstart=instrRev(str,"/")if start=1 thenurl="/"elseurl=left(str,start)end ifurl=urlhead&urlelseif left(str,3)="../" thenstr1=mid(str,inStrRev(str,"../")+2)ar=split(str,"../")lv=ubound(ar)+1ar=split(path,"/")url="/"for i=1 to (ubound(ar)-lv)url=url&ar(i)nexturl=url&str1url=urlhead&urlelseurl=urlhead&strend ifgetvirtual=urlend function
推荐阅读
ASP得到文件的大小类型最后修改时间
要得到生成的HTML文件的最后修改时间,写了一个函数,有简单的判断.
实例:
2005-11-10 19:33:44 ASP 文件 6.83 KB
把下面文件另存为mofei.asp文件,运行即可,要FSO支持.
<%Function fsofiledatemofei(sfile)'>>>详细阅读
本文标题:一次性下载远程页面上的所有内容第1/2页
地址:http://www.17bianji.com/kaifa2/ASP/33331.html
1/2 1