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.