Use ASP to retrieve the image address in HTML

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.