Parse the image address with a regular and use the XMLHTTP component to save it (a good thing oh, I've been looking for it for a long time!) )

Source: Internet
Author: User
Now based on the Web page of the HTML editor in the news system, the article system more and more widely used, a Web page can maintain the original style, while the picture can also be maintained on this page. However, in the use of the process, if the pasted pages of the picture is deleted, you will leave a large "X" on their own page, affecting the beautiful. Previously had to save this picture, and then uploaded to the server, this is really troublesome. Can I have the server automatically download pictures saved on the server and replace the links on the page? The answer is yes.
Three steps are required to implement this feature:
One, get the address of the picture in the original page. There are many ways to use split strings, or you can use regular matches. It is proved by practice that regular matching is the simplest. The addresses of the analyzed pictures are kept in the tag. We can get all this tag first. The process is as follows:
Set objregexp = New Regexp ' Set Configuration object
Objregexp.ignorecase = True ' ignores case
Objregexp.global = True ' Set to Full-text search
Objregexp.pattern = " tag, And then take out the image inside the Getimgs function behind the address is to achieve the latter function.
Strs=trim (str)
Set matches =objregexp.execute (STRs) ' Starts execution configuration
For the Match in matches
Retstr = Retstr &getimgs (match.value) ' performs a second-round match
Next
All the pictures inside are such src= "http://picture address", so you can get the exact picture address:
function Getimgs (str)
Getimgs= ""
Set OBJREGEXP1 = New Regexp
Objregexp1.ignorecase = True
Objregexp1.global = True
Objregexp1.pattern = "http://.+?" "" ' Take out the address inside.
Set Mm=objregexp1.execute (str)
For each Match1 in mm
getimgs=getimgs& "| |" &left (Match1.value,len (Match1.value)-1) ' Put the address of the inside string up for backup
Next
End Function
With all the pictures in the address, we can do the second step of the operation.
Second, download the picture and save it on the server. This can be divided into two steps: one is to get the content of the picture, the other is saved on the server. The contents of the picture are achieved by using the following function:
function gethttppage (URL)
On Error Resume Next
Dim http
Set Http=server.createobject ("Msxml2.xmlhttp") ' uses XMLHTTP method to get the contents of a picture
Http.open "Get", Url,false

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.