《2022年将远程页面的所有内容下载到本地源码精华教程.docx》由会员分享,可在线阅读,更多相关《2022年将远程页面的所有内容下载到本地源码精华教程.docx(12页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、2022年将远程页面的所有内容下载到本地源码精华教程代码的运用:将下面的代码保存为downfile.asp放到你的站点一个书目下,然后在那个书目里面建立一个叫downfile的文件夹,全部得到的内容都将保存在downfile文件夹里。在阅读器中输入http:/你的地址/downfile.asp?url=那么就将百度首页的全部文件都下载到本地的那个叫downfile的文件夹中.这个代码比你的手工OE可要舒适多了,而且会将获得的文件,根据原来远程的路径,建立文件夹,分类别保存文件.<%'#'代码的主体函数部分均源自于网络'修改:blue2022'转载注明:落伍
2、者'#'设置超时的时间Server.ScriptTimeout=9999'#'文件保存函数'#function SaveToFile(from,tofile)on error resume nextdim geturl,objStream,imgsgeturl=trim(from)Mybyval=getHTTPstr(geturl)Set objStream = Server.createObject(ADODB.Stream)objStream.Type =1objStream.Openobjstream.write Mybyvalobjstream.
3、SaveToFile tofile,2objstream.Close()set objstream=nothingif err.number<>0 then err.Clearend function'#'字符处理替换'#function geturlencodel(byval url)'中文文件名转换Dim i,codegeturlencodel=if trim(Url)= then exit functionfor i=1 to len(Url)code=Asc(mid(Url,i,1)if code<0 Then code = code
4、+ 65536If code>255 Thengeturlencodel=geturlencodel%Left(Hex(Code),2)%Right(Hex(Code),2)elsegeturlencodel=geturlencodelmid(Url,i,1)end ifnextend function'#'XML获得远程页面起先'#function getHTTPPage(url)on error resume nextdim httpset http=Server.createobject(Msxml2.XMLHTTP)Http.open GET,url,fa
5、lseHttp.send()if Http.readystate<>4 then exit functiongetHTTPPage=bytes2BSTR(Http.responseBody)set http=nothingif err.number<>0 then err.Clearend functionFunction bytes2BSTR(vIn)dim strReturndim i,ThisCharCode,NextCharCodestrReturn =For i = 1 To LenB(vIn)ThisCharCode = AscB(MidB(vIn,i,1)
6、If ThisCharCode < H80 ThenstrReturn = strReturn Chr(ThisCharCode)ElseNextCharCode = AscB(MidB(vIn,i+1,1)strReturn = strReturn Chr(CLng(ThisCharCode) * H100 + CInt(NextCharCode)i = i + 1End IfNextbytes2BSTR = strReturnEnd Function'#'XML获得远程页面结束,这段是小偷程序都通用的部分'#'#'分解地址,取得文件名'
7、#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'#'获得远程页面函数'#fun
8、ction getHTTPstr(url)on error resume nextdim httpset http=server.createobject(MSXML2.XMLHTTP)Http.open GET,url,falseHttp.send()if Http.readystate<>4 then exit functiongetHTTPstr=Http.responseBodyset http=nothingif err.number<>0 then err.Clearend function'#'FSO处理函数,创建书目'#Funct
9、ion createDIR(ByVal LocalPath) '建立书目的程序,假如有多级书目,则一级一级的创建On Error Resume NextLocalPath = Replace(LocalPath, , /)Set FileObject = server.createObject(Scripting.FileSystemObject)patharr = Split(LocalPath, /)path_level = UBound(patharr)For I = 0 To path_levelIf I = 0 Then pathtmp = patharr(0) / Else
10、 pathtmp = pathtmp patharr(I) /cpath = Left(pathtmp, Len(pathtmp) - 1)If Not FileObject.FolderExists(cpath) Then FileObject.createFolder cpathNextSet FileObject = NothingIf Err.Number <> 0 ThencreateDIR = FalseErr.ClearElsecreateDIR = TrueEnd IfEnd Functionfunction GetfileExt(byval filename)fi
11、leExt_a=split(filename,.)GetfileExt=lcase(fileExt_a(ubound(fileExt_a)end function'#'如何获得虚拟的路径'#function getvirtual(str,path,urlhead)if left(str,7)=http:/http:/ thenurl=strelseif left(str,1)=/ thenstart=instrRev(str,/)if start=1 thenurl=/elseurl=left(str,start)end ifurl=urlheadurlelseif l
12、eft(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=urlar(i)nexturl=urlstr1url=urlheadurlelseurl=urlheadstrend ifgetvirtual=urlend function'下面是示范性的代码dim dlpath'建立一个文件夹,以便存放这些获得的数据virtual=/downfile/truepath=server
13、.MapPath(virtual)if request(url)<> thenurl=request(url)fn=getFileName(url)urlhead=left(url,(instr(replace(url,/,),/)+1)urlpath=replace(left(url,instrRev(url,/),urlhead,)strContent = getHTTPPage(url)mystr=strContentSet objRegExp = New RegexpobjRegExp.IgnoreCase = TrueobjRegExp.Global = TrueobjR
14、egExp.Pattern = (srchref)=.>+?Set Matches =objRegExp.Execute(strContent)For Each Match in Matchesstr=Match.Valuestr=replace(str,src=,)str=replace(str,href=,)str=replace(str,)str=replace(str,',)filename=GetfileName(str)getRet=getVirtual(str,urlpath,urlhead)temp=Replace(getRet,/,*)start=instr(t
15、emp,/)endt=instrRev(temp,/)-start+1if start>0 thenrepl=virtualmid(temp,start)'response.Write repl<br>mystr=Replace(mystr,str,repl)dir=mid(temp,start,endt)temp=truepathReplace(dir,/,)createDir(temp)response.Write getRettempfilename<br>response.Write 胜利取得filename这个文件<br>response.Write 并将filename保存在temp<br><br>response.Write <HR>SaveToFile getRet,tempfilenameend ifNextset Matches=nothingelseresponse.write 请输入一个地址!end if%>经测试,还真不错!不过,最好在页首加入<%LANGUAGE=VBSCRIPT CODEPAGE=936%>,否则提示页面会是乱码!(出处: