从网页中获取图片链接的方法。

祁嘉言
2023-12-01

获取海量图片的方法。

vbs脚本,windows下执行。
指定文件夹,提取所有文件中图片链接。


dim FileName,fs,foldername
foldername = "亦道云www.1os.top"
If foldername = "" Then
wscript.quit
End If

strPattern = "https?:+[^\]]+(\.(gif|png|jpg|jpeg|webp|svg|psd|bmp|tif)\))"
Set fs = CreateObject("scripting.filesystemobject")
Set outFile = fs.CreateTextFile("out-url.txt", True)
Set folder = fs.getfolder(foldername)
Set Files = folder.Files
For Each i In Files
       textline=loadEncode(i.path)
       urlhttp=RegExpTest(strPattern,textline)
       If urlhttp<>"" Then
          urlhttp =replace(urlhttp,")","")
          outFile.WriteLine(urlhttp)
       End If
Next
outFile.Close
Set outFile=Nothing

Function RegExpTest(patrn, strng)
   Dim regEx, Match, Matches   ' 建立变量。
   Set regEx = New RegExp   ' 建立正则表达式。
   regEx.Pattern = patrn   ' 设置模式。
   regEx.IgnoreCase = True   ' 设置是否区分大小写。
   regEx.Global = True   ' 设置全程可用性。
   Set Matches = regEx.Execute(strng)   ' 执行搜索。
   RetStr=""
   For Each Match in Matches      ' 遍历 Matches 集合。
     'msgbox Match.value 
     n_match=Instr(RetStr,Match.value)
     If n_match=0 Then
       'RetStr = RetStr & Match.value &vbcrlf 
       RetStr = RetStr & Match.value &vbcrlf 
     End if      
   Next
   RegExpTest = RetStr
End Function

Function loadEncode(filePath)
    Dim stm
    Set stm = CreateObject("Adodb.Stream")
    stm.Type = 2
    stm.mode = 3
    stm.charset = "UTF-8"
    stm.Open
    stm.LoadFromFile filePath
    loadEncode= stm.readtext
    stm.close
    Set stm = nothing
End Function

 类似资料: