Baidu space backup script baidublogbak.vbs code analysis

Time:2020-6-3

‘usage example:
‘cscript bak.vbs Baidu user name page I to page n directory list.htm user name password
‘for example, my blgo example:
‘cscript baidublogbak.vbs myvbscript 0 3 url.htm myvbscript mima
‘indicates that from page 0 to page 3, the total number of pages of the blog is open http://hi.baidu.com/ The user name / blog / index / 0 can be seen. url.htm It’s a directory list
‘note that Baidu counts from 0 pages
‘if the user name and password are casually written, they can be backed up, but private documents cannot be backed up
‘it is recommended to back up several pages. It is better to create a separate directory to bak.vbs Put it in and MHT documents will be generated in the current directory. For some network reasons, some cannot be MHT, please check url.htm Directory list check
‘====================================================================================================

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 password”
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”

Do
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

Do
Wscript.Sleep 200
Loop Until ie.ReadyState=4

wscript.echo “Saving page” & n & “
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