Experience exchange of Acquisition programming (III.)--saving web pages

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Save Web page (Stream application)

We used three lines of code to complete the download of the Web page, but the contents of the download is garbled, here we solve the garbled problem and save it into a TXT file.

There are two ways to create txt files: First, the FSO is a common way to create, but in conjunction with the use of XMLHTTP will often appear some problems, here no longer detailed introduction. Second, the use of Stream,stream is XMLHTTP's best partner, we come down to introduce the use of the following methods:

1. Create Stream object

Code: Set MSS = CreateObject ("ADODB.") Stream ")

2. Set parameters

Code:

MSs. Mode = 3

MSs. Type = 1

Where mode mode, when the value is 1 for read mode, 2 for write mode, 3 for read-write mode, here we for the operation is not limited to set it to 3;type for the return data type, 1 for binary,2 text, we set to 1

3, open the object

Code: Mss.open ()

4. Write Data

Code: MSS. Write ("content")

Write is a method of the stream that is used to write data.

5. Save to File

MSs. SaveToFile (Filename,[options])

SaveToFile method, this method is used to save content to a file, where filename is a filename, you can write casually, options for the access option, required, in order to avoid content overlay we set to 2. (Please support website http://www.99jpw.cn)

6, close the object

Code: Set MSS = Nothing

Closes the object and frees up memory.

The above is a few steps to save the content, for the sake of understanding, we illustrate:

Still with "Dot Dot ticket network http://www.66666999.com" as an example:

Url= "Http://www.66666999.com"

Set ms = CreateObject ("Microsoft.XMLHTTP")

Ms. Open ' get ', url, False

Ms. Send ()

Code to download Web pages

Set MSS = CreateObject ("ADODB.") Stream ")

MSs. Mode = 3

MSs. Type = 1

Mss.open ()

MSs. Write (Ms.responsebody)

MSs. SaveToFile ("1.txt", 2)

Set mss=nothing

Set ms=nothing

Run the above code we can see that the program has saved the http://www.99jpw.cn to 1.txt files, and garbled problem has been resolved.

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.