The main principle of using ASP to retrieve the image addresses in HTML is to use regular expressions to determine the attributes. This will be useful in the collection program.
The function is as follows:
The following is a reference clip:
Function ShowPic (str)
Set objRegExp = New Regexp 'to Set the configuration object
ObjRegExp. IgnoreCase = true' case insensitive
ObjRegExp. Global = true' is set to full-text search.
ObjRegExp. Pattern = " "
'To ensure that the image address can be accurately retrieved, there are two layers of configuration: first, find the img label in it, and then retrieve the getimgs function behind the image address in it to implement the next function.
Strs = trim (str)
Set Matches = objRegExp. Execute (strs)'
For Each Match in Matches
RetStr = RetStr & getimgs (Match. Value)'
Next
ShowPic = RetStr
End Function
Function getimgs (str)
Getimgs = ""
Set objRegExp1 = New Regexp
ObjRegExp1.IgnoreCase = True
ObjRegExp1.Global = True
ObjRegExp1.Pattern = "http: //. +? "'Retrieve the address
Set mm = objRegExp1.Execute (str)
For Each mattings in mm
Getimgs = getimgs & left (Match1.Value, len (Match1.Value)-1) & "|" 'concatenates the addresses in the string for backup.
Next
End Function
'Retrieve image content
Function getHTTPPage (url)
On error resume next
Dim http
Set http = server. createobject ("MSXML2.XMLHTTP") 'uses the xmlhttp method to obtain the image content
Http. open "GET", url, false
Http. send ()
If Http. readystate <> 4 then
Exit function
End if
GetHTTPPage = Http. responseBody
Set http = nothing
If err. number <> 0 then err. Clear
End function
'Save the image
Function saveimage (from, tofile)
Dim geturl, objStream, imgs
Geturl = trim (from)
Imgs = gethttppage (geturl) 'The process of obtaining the rest content of an image
Set objStream = Server. CreateObject ("ADODB. Stream") 'creates an ADODB. Stream object, which must be of version ADO 2.5 or later.
ObjStream. Type = 1' open in binary mode
ObjStream. Open
Objstream. write imgs write string content to buffer
Objstream. SaveToFile server. mappath (tofile), 2'-write the Buffered content to the file
Objstream. Close () 'Close the object
Set objstream = nothing
End function
'Call the instance
Dim strpic, I, fname
Strpic = ShowPic ("
")
Strpic = Split (strpic, "| ")
If UBound (strpic)> 0 Then
For I = 0 To UBound (strpic)-1
'Save the image
Fname = cstr (I & mid (strpic (I), faster Rev (strpic (I ),".")))
Saveimage (strpic (I), fname)
Next
Else
End If