J'ai lu un article sur le téléchargement des images dans la page Web.
Download.asp? Url = la page Web que vous souhaitez télécharger
Télécharger.asp Code comme suit:
| Ce qui suit est le fragment de code: % Server.scriptTimeout = 9999 Fonction Savetofile (de, tofile) Sur l'erreur reprendre ensuite Dim geturl, objstream, imgs getUrl = trim (de) MyByVal = getTTPSTR (getUrl) Définir ObjStream = Server.CreateObject (Adodb.Stream) objstream.type = 1 objstream.open objstream.write mybyval objstream.savetofile tofile, 2 objstream.close () définir objstream = rien Si err.number <> 0 le err.clear fonction finale Fonction geturlencodel (URL ByVal) 'Conversion du nom de fichier chinois Dim I, code geturlencodel = Si TRIM (URL) = puis la fonction de sortie pour i = 1 à Len (URL) Code = ASC (Mid (URL, I, 1)) Si code <0 thatn code = code 65536 Si le code > 255 alors Geturlencodel = geturlencodel &% & gauche (hex (code), 2) &% & droite (hex (code), 2) autre geturlencodel = geturlencodel & mid (url, i, 1) terminer si suivant fonction finale Fonction gethttppage (URL) Sur l'erreur reprendre ensuite DIM HTTP Définir http = server.createObject (msxml2.xmlhttp) Http.open get, url, false Http.send () Si http.readystate <> 4 la fonction de sortie GethTTPPAGE = BYTES2BSTR (Http.ResponseBody) définir http = rien Si err.number <> 0 le err.clear fonction finale Fonction bytes2bSTR (VIN) sombre Strreturn Dim I, ThisCharcode, NextCharcode Streturn = Pour i = 1 à Lenb (vin) ThisCharcode = ASCB (midb (vin, i, 1)) Si thischarcode <& h80 alors Streturn = Strreturn & Chr (ThisCharcode) Autre NextCharcode = ASCB (Midb (vin, i 1,1))) STRRETURN = STRRETURN & CHR (CLNG (ThisCharcode) * & H100 Cint (NextCharcode)) i = i 1 Terminer si Suivant bytes2bstr = STRRETURN Fonction finale Fonction getFileName (nom de fichier byVal) Si instr (nom de fichier, /) > 0 alors filext_a = split (nom de fichier, /) GetFileName = lCase (fileExt_a (ubound (filext_a)) Si instr (getFileName,?) > 0 alors getFileName = Left (getFileName, instlin (getFileName,?) - 1) terminer si autre getFileName = nom de fichier terminer si fonction finale Fonction gethttpstr (URL) Sur l'erreur reprendre ensuite DIM HTTP Définir http = server.createObject (msxml2.xmlhttp) Http.open get, url, false Http.send () Si http.readystate <> 4 la fonction de sortie Gethttpstr = http.Responsebody définir http = rien Si err.number <> 0 le err.clear fonction finale Fonction Createir (ByVal LocalPath) pour créer un programme d'annuaire, s'il y a plusieurs répertoires, puis le niveau et une création d'un niveau Sur l'erreur reprendre ensuite LocalPath = remplacer (localPath, /, /) Set fileObject = server.createObject (scripting.filesystemObject) patharr = fendre (localPath, /) path_level = ubound (patharr) Pour i = 0 à path_level Si i = 0 thatn pathtmp = patharr (0) & / else pathtmp = pathtmp & patharr (i) & / Cpath = gauche (pathtmp, len (pathtmp) - 1) Si non fileObject.foldrexist (cPath), le fileObject.createFolder cPath Suivant Set fileObject = rien Si err.number <> 0 alors CreateDir = false Err.Clear Autre CreateDir = true Terminer si Fonction finale Fonction getFileExt (nom de fichier ByVal) filext_a = split (nom de fichier,.) GetFileExt = lCase (FileExt_A (ubound (filext_a)) fonction finale Fonction getVirtual (str, chemin, Urlhead) Si vous êtes laissé (str, 7) = http: // alors url = str elseif gauche (str, 1) = / alors Start = instrrev (str, /) Si démarrer = 1 alors url = / autre url = gauche (str, start) terminer si url = Urlhead & URL elseif gauche (str, 3) = ../ alors Str1 = mid (str, instrrev (str, ../) 2) 2) Ar = Split (str, ../) lv = ubound (ar) 1 Ar = Split (chemin, /) url = / pour i = 1 à (ubound (ar) -lv) url = url & ar (i) suivant url = url & str1 url = Urlhead & URL autre url = Urlhead & Strong terminer si getVirtual = URL fonction finale 'Exemple de code DIM DLPATH virtual = / download / truepath = server.mappath (virtual) Si demande (URL) <> alors url = demande (URL) fn = getFileName (URL) Urlhead = Left (URL, (instant (Remplacer (URL, //,), /)) urlPath = remplacer (gauche (url, instrrrev (url, /)), Urlhead,) StrContent = gethttppage (URL) Mystr = strContent Définir objregexp = new regexp objregexp.ignorecase = true objregexp.global = true objregexp.Pattern = (src | href) =. Set Matchs = objregexp.execute (strContent) Pour chaque match dans les matchs str = match.value str = remplacer (str, src =,) str = remplacer (str, href =,) str = remplacer (str ,,) str = remplacer (str, ',) filename = getFileName (str) getret = getVirtual (str, urlpath, urlhead) temp = remplacer (getret, //, **) Start = instr (temp, /) Endt = instrrev (temp, /) - démarrer 1 Si démarrer > 0 alors Rep = virtual & mid (temp, start) & 'Response.Write REPT & <br> mystr = remplacer (mystr, str, rep) Dir = mid (temp, start, endt) temp = truepath & remplacer (dir, /,) Crééir (temp) 'Response.Write Getret & || & Temp & FileName & <br> <br> SaveTofile Getret, test et nom de fichier terminer si Suivant Set Matchs = Rien terminer si %> |