Baidu Space Backup script baidublogbak.vbs code Analysis _vbs

Source: Internet
Author: User
' Usage examples:
' cscript bak.vbs Baidu user Name page I to nth directory list. htm username password
' Example of my Blgo example:
' cscript baidublogbak.vbs myvbscript 0 3 url.htm myvbscript mima
' indicates that pages from page No. 0 to page 3rd, the total number of blog pages Open http://hi.baidu.com/username/blog/index/0 can be seen. Url.htm is storing a list of directories
' Note that Baidu is counted from 0 pages
' If the username and password are written in a random way, you can back it up, but you cannot back up private documents
' Recommend several pages of backup, preferably a separate directory to put Bak.vbs, will be in the current directory to generate MHT documents. Because some network reason, some cannot become mht, please check with url.htm directory list
'====================================================================================================

On Error Resume Next
if (LCase right (wscript.fullname,11) = "Wscript.exe") Then
WScript.Echo "Execute it under the Cmd.exe plz! Thx."
Wscript.Quit
End If

Const adsavecreatenotexist = 1
Const Adsavecreateoverwrite = 2
Const adTypeBinary = 1
Const adTypeText = 2

Set args = WScript.Arguments

If args. Count = 0 Then
WScript.Echo "Usage:cscript Baidublogbak.vbs blogname i n url.htm username"
Wscript.Quit 1
End If

Set objmessage = CreateObject ("CDO.") Message ")
Set ie=wscript.createobject ("Internetexplorer.application")
Ie.visible=true
Ie.navigate "Http://passport.baidu.com/?login"

Todo
Wscript.Sleep 200
Loop Until ie. Readystate=4
Ie.document.getElementById ("username"). Value=args. Item (4)
Ie.document.getElementById ("password"). Value=args. Item (5)
Tj=ie.document.getelementsbytagname ("form")
Tj.submit
Wscript.Sleep 10000
Sub SaveToFile (MSG, Fn)
Dim STRM, Dsk
Set strm = CreateObject ("ADODB. Stream ")
Strm.type = adTypeText
Strm.charset = "gb2312"
Strm.open
Set Dsk = Msg.datasource
Dsk.savetoobject strm, "_stream"
Strm.savetofile Fn, Adsavecreateoverwrite
End Sub

For N=args. Item (1) to args. Item (2) Step 1

Url= "http://hi.baidu.com/" &args. Item (0) & "/blog/index/" &n
Ie. Navigate URL
Ie.visible=false

While IE. Busy
Wscript.Sleep 100
Wend

Todo
Wscript.Sleep 200
Loop Until ie. Readystate=4

WScript.Echo "&n&" page
Wscript.Sleep 3000

For i=0 to IE. Document.links.length-1
If InStrRev (ie. Document.links (i). href, "blog/item/", -1,1 <> 0 and InStrRev (ie. Document.links (i). innertext, "Browse", -1,1) = 0 and InStrRev (ie. Document.links (i). href, "#comment", -1,1) = 0 and InStrRev (ie. Document.links (i). href, "Cmtid", -1,1) = 0then
WScript.Echo ie. Document.links (i). href & "| |" &ie. Document.links (i) innertext
CreateObject ("Scripting.FileSystemObject"). OpenTextFile (args. Item (3), 8,true,0). WriteLine (ie. Document.links (i). href & "| |" &ie. Document.links (i). innertext)
Objmessage.createmhtmlbody ie. Document.links (i). href
SaveToFile objmessage, ie. Document.links (i) .innertext& ". mht"
End If

Next

Next

Ie.quit
Set ie=nothing

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.