Eu leu um artigo sobre o download da página da web
Download.asp?
Download.asp código da seguinte forma:
| A seguir, o fragmento de código: % Server.scriptTimeout = 9999 Função savetofile (de, tofile) Em erro de erro em seguida Dim geturl, objstream, imgs geturl = Trim (de) Mybyval = getttpstr (geturl) Set objStream = server.createObject (adodb.stream) objstream.type = 1 objstream.open objstream.write mybyval Objstream.Savetofile Tofile, 2 objstream.close () definir objstream = nada se err.number <> 0 o err.clear Função final Função geturlencodel (byval url) 'nomes de arquivo chinês conversão Dim i, código geturlencodel = Se TRIM (URL) = Função de saída para i = 1 a len (url) Código = ASC (MID (URL, i, 1)) Se código <0 esse código = código 65536 Se código > 255 então Geturlencodel = geturlencodel &%& deixado (hexade outro geturlencodel = geturlencodel & Mid (URL, i, 1) final se próximo Função final Função Gethttppage (URL) Em erro de erro em seguida Dim http Definir http = server.createObject (msxml2.xmlHttp) Http.open get, url, falso Http.send () Se http.readystate <> 4 a função de saída Gethttppage = bytes2bst (http.Responsebody) Definir http = nada se err.number <> 0 o err.clear Função final Função bytes2bstr (vin) Dim strreturn Dim i, thischarcode, nextcharcode Strreturn = Para i = 1 a lenb (vin) ThisCharcode = ASCB (MIDB (VIN, i, 1)) Se thischarcode <& h80 então Strreturn = strreturn & ch (thischarcode) Outro Nextcharcode = ASCB (MIDB (VIN, I 1,1))) Strreturn = strreturn & ch (clng (thischarcode) * & h100 cint (nextcharcode)) i = i 1 Final se Próximo bytes2bstr = strreturn Função final Função getFilename (nome do arquivo byval) Se Instr (nome do arquivo,/) > 0 então filext_a = split (nome do arquivo,/) GetFilename = lcase (FILEEXT_A (UBOUND (FILEXT_A)) Se Instr (getFileName ,?) > 0 então getFilename = esquerda (getFileName, instrum (getFileName ,?)-1) final se outro getFilename = nome do arquivo final se Função final Função gethttpstr (url) Em erro de erro em seguida Dim http Definir http = server.createObject (msxml2.xmlHttp) Http.open get, url, falso Http.send () Se http.readystate <> 4 a função de saída Gethttpstr = http.ResponseBody Definir http = nada se err.number <> 0 o err.clear Função final Função CreatedIr (ByVal LocalPath) para criar um programa de diretório, se houver um diretório múltiplo, depois a criação de nível e um nível Em erro de erro em seguida LocalPath = Substitua (LocalPath, /, /) Set fileObject = server.createObject (script.filesystemoBject) PATHARR = SPLIT (LocalPath, /) path_level = ubound (patharr) Para i = 0 para path_level Se i = 0 thatn patttmp = patharr (0) e / else Pathtmp = pathtmp & patharr (i) & / Cpath = esquerda (pathtmp, len (pathtmp) - 1) Se não for fileObject.foldrexist (cpath), o FileObject.CreateFolder CPath Próximo Set fileObject = nada Se err.number <> 0 então CreateDir = false Err.clear Outro CreativeIr = true Final se Função final Função getFileExt (nome do arquivo byval) filext_a = split (nome do arquivo ,.) GetFileExt = lcase (FILEEXT_A (UBOUND (FILEXT_A)) Função final Função getvirtual (str, caminho, urlhead) se esquerdo (str, 7) = http: // então url = str elseif esquerdo (str, 1) =/ então Start = Instrrev (str,/) Se inicialmente = 1 então url =//// outro url = esquerda (str, start) final se url = urlhead & url elseif esquerdo (str, 3) = ../ então STR1 = MID (STR, Instrrev (str, ../) 2) 2) AR = Split (str, ../) lv = ubound (ar) 1 AR = Split (Path,/) url =//// para i = 1 a (ubound (ar) -lv) url = url & ar (i) próximo url = url & str1 url = urlhead & url outro url = urlhead & forte final se getVirtual = url Função final 'Código de exemplo DL DLPATH virtual =/download/ truepath = server.mappath (virtual) se solicitar (url) <> então url = solicitação (URL) fn = getFileName (URL) urlhead = esquerda (URL, (Instr (substituir (url, //,),/)) urlpath = substituir (esquerda (URL, Instrrev (url,/)), urlhead,) StrContent = Gethttppage (URL) Mystr = strContent Defina objregexp = novo regexp objregexp.ignorecase = true objregexp.global = true objregexp.pattern = (src | href) =. SET MOCHES = objregexp.execute (strContent) Para cada partida em partidas str = match.value str = substituir (str, src =,) str = substituir (str, href =,) str = substituir (str ,,) str = substituir (str, ',) arquivo de arquivo = getFileName (str) getRet = getVirtual (str, urlpath, urlhead) temp = substituir (getret, //, **) Start = Instr (temp,/) ENDT = Instrrev (temp,/)-Iniciar 1 Se iniciar > 0 então Repl = Virtual & Mid (Temp, Start) & 'Response.Write Repl & <br> mystr = substituir (mystr, str, repl) Dir = Mid (Temp, Start, Endt) Temp = Truepath & Substituir (dir,/,/) CreativeIR (temp) 'Response.write getret & || & temp & filename & <br> <br> Savetofile Getret, Test & FileName final se Próximo Set Matches = nada final se %> |