Use asp to automatically parse the image address in the webpage and save it to the local server.

Source: Internet
Author: User
Currently, HTML editors based on web pages are widely used in news systems and document systems. A webpage can stick to the original style, and images can also be kept on this page. However, if the image on the pasted page is deleted, a large "X" will be left on the page, affecting the appearance. In the past, I had to save the image and upload it to the server again. This is really troublesome. Can I have the server automatically download images stored on the server and replace the links on the page? The answer is yes.
To implement this function, three steps are required:
1. Obtain the image address on the original page. There are many methods, which can be used to separate strings or use regular expressions for matching. Practice has proved that regular expression matching is the simplest. The addresses of the analyzed images are saved in the label. We can obtain all the tags first. The process is as follows:
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 label in it, then, the getimgs function behind the image address is used to implement the next function.
Strs = trim (str)
Set Matches = objRegExp. Execute (strs)'
For Each Match in Matches
? RetStr = RetStr & getimgs (Match. Value)'
Next
All the images are in the src = "http: // Image Address", so you can get the exact image address as follows:
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
After obtaining the addresses of all images, we can perform step 2 operations.
2. Download the image and save it on the server. This can be divided into two steps: one is to get the image content, and the other is to save it on the server. The following function is used to obtain the image content:
All the images are in the src = "http: // Image Address", so you can get the exact image address as follows:
Function getimgs (str)
Getimgs = ""
Set objRegExp1 = New Regexp
Related Article

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.