Este artigo compartilha principalmente o código da função para a substituição e salvamento de imagens remotas.
O ASP usa funções para substituir e salvar figuras remotas, completar as funções de coleta e extrair imagens automaticamente, julgar automaticamente repetir imagens na função, analisar de forma inteligente o caminho do link e convertê -lo em um endereço de imagem relativo e salvá -lo no diretório do site que você Especificado. Ao mesmo tempo, esse código também é uma função de processamento importante no programa de coleta.
- FunctionReplacesveroteroteFile (Constr, Strinstalldir, Strchanneldir, Savetf, Tisturl)
- IfConstr = $ false $ orconstr = orStrInstalldir = orstrchanneldir = então
- SubstituaveroteroteFile = Constr
- Saída de saída
- Endif
- Dimtempstr, Tempstr2, Tempstr3, Re, Matches, Match, Temppi, Temparray, Temparray2
- Setre = newRegexp
- Re.IGNORECASE = true
- Re.global = true
- Re.pattern =]>
- SetMatches = re.execute (constr)
- ForeachMatchinMatches
- Iftempstr <> então
- Tempstr = tempstr & $ array $ & match.value
- Outro
- Tempstr = match.value
- Endif
- Próximo
- Iftempstr <> então
- Temparray = split (tempstr, $ array $)
- Tempstr =
- Fortempi = 0Toubound (Temparray)
- Re.pattern = src/s*=/s*.+?/. (Gif | jpg | bmp | jpeg | psd | png | svg | dxf | wmf | tiff)
- SetMatches = re.execute (Temparray (tempi))
- ForeachMatchinMatches
- Iftempstr <> então
- Tempstr = tempstr & $ array $ & match.value
- Outro
- Tempstr = match.value
- Endif
- Próximo
- Próximo
- Endif
- Iftempstr <> então
- Re.pattern = src/s*=/s*
- Tempstr = re.Replace (tempstr,)
- Endif
- SetMatches = nada
- Setre = nada
- Iftempstr = orisnull (tempstr) = truethen
- SubstituaveroteroteFile = Constr
- Saída de saída
- Endif
- Tempstr = substituir (tempstr ,,)
- Tempstr = substituir (tempstr, ',)
- Tempstr = substituir (tempstr ,,)
- DimRemoteFileurl, SavePath, PathTemp, dtnow, strfilename, strfileType, arsaveFileName, rannum, ARR_PATH
- Dtnow = agora ()
- IfSavetf = Truethen
- SavePath = strChanneldir &/& Year (dtnow) & Right (0 e mês (dtnow), 2) &/
- Caminho do link da resposta.write: & salvath &
- Arr_path = split (savepath,/)
- PathTemp =
- Fortempi = 0TOUBOUND (ARR_PATH)
- Iftempi = 0then
- PathTemp = arr_path (0) &/
- ElseIftempi = ubound (arr_path) então
- Exitfor
- Outro
- PathTemp = PathTemp & ARR_Path (Tempi) &/
- Endif
- Ifcheckdir (pathTemp) = falseten
- Ifmakenewsdir (pathtemp) = falseten
- Savetf = false
- Exitfor
- Endif
- Endif
- Próximo
- Endif
- 'Remova as imagens duplicadas
- Temparray = split (tempstr, $ array $)
- Tempstr =
- Fortempi = 0Toubound (Temparray)
- Ifinstr (lcase (tempstr), lcase (temparray (temppi))) <1then
- Tempstr = tempstr & $ array $ & temparray (temppi)
- Endif
- Próximo
- Tempstr = direita (tempstr, len (tempstr) -7)
- Temparray = split (tempstr, $ array $)
- 'Converter endereço de imagem relativa
- Tempstr =
- Fortempi = 0Toubound (Temparray)
- Tempstr = tempstr & $ array $ e definitário (temparray (temppi), tisturl)
- Próximo
- Tempstr = direita (tempstr, len (tempstr) -7)
- Tempstr = substituir (tempstr, chr (0),)
- Temparray2 = split (tempstr, $ array $)
- Tempstr =
- 'Substituição de imagem/salvar
- Setre = newRegexp
- Re.IGNORECASE = true
- Re.global = true
- Fortempi = 0Toubound (Temparray2)
- RemoteFileurl = Temparray2 (Tempi)
- IfRemoteFileurl <> $ false $ eSavetf = imagem de Truethen
- ArrSaveFilename = Split (RemoteFileurl ,.)
- strFileType = lcase (arsaveFileName (ubound (arsaveFileName))) 'tipo de arquivo
- Ifstrfiletype = aspostrfiletype = ASAORSTRFILETYPE = ASPXORSTRFILETYPE = CERORSTRFILETYPE = CDXORSTRFILETYPE = exEorStrFilEType = rarostrFilEType = zipthen
- Uploadfiles =
- SubstituaveroteroteFile = Constr
- Saída de saída
- Endif
- Randomizar
- Rannum = int (900*rnd) +100
- strfilename = ano (dtnow) e direita (0 e mês (dtnow), 2) e direita (0 & dia (dtnow), 2) e direita (0 & hour (dtnow), 2) e direita (0 & minuto (dtnow), 2) e direita (0 & segundo (dtnow), 2 ) & Right (0 & Second (dtnow), 2) e Rannum &. & strfileType
- Re.pattern = temparray (tempi)
- IfsaveRemoteFile (SAVEPATH & STRFILENAME, RemoteFileurl) = Truethen
- '************************************
- PathTemp = SavePath & StrfileName
- Construção = re.Replace (construt, pathtemp)
- Re.pattern = strinstalldir & strchanneldir &//////////////
- Uploadfiles = uploadfiles & | & re.Replace (salvApath & strfileName,)
- Outro
- PathTemp = RemoteFileurl
- Construção = re.Replace (construt, pathtemp)
- 'Uploadfiles = uploadfiles & | & remotefileurl
- Endif
- ElseifRemoteFileurl <> $ false $ eSavetf = falsethen 'não salva a imagem
- Re.pattern = temparray (tempi)
- Constr = re.Replace (construt, remotefileurl)
- Uploadfiles = uploadfiles & | & remotefileurl
- Endif
- Próximo
- Setre = nada
- Ifuploadfiles <> então
- Uploadfiles = à direita (Filme de upload, len (uploadfiles) -1)
- Endif
- SubstituaveroteroteFile = Constr
- Função final
Função Parâmetro Descrição:
Construt: a string para substituir
Parâmetros: Savetf: Se deve salvar o arquivo, False não salva, verdadeiro salvar
Parâmetros: Tisturl: endereço da página atual
O exposto acima é o código para a substituição do ASP e salvar a função de imagem remota, espero que seja útil para o aprendizado de todos.