百度空間備份腳本baidublogbak.vbs代碼分析
更新時(shí)間:2008年08月16日 21:31:35 作者:
cscript bak.vbs 百度用戶(hù)名 第I頁(yè) 至第n頁(yè) 目錄列表.htm 用戶(hù)名 密碼
'用法示例:
'cscript bak.vbs 百度用戶(hù)名 第I頁(yè) 至第n頁(yè) 目錄列表.htm 用戶(hù)名 密碼
'例如我的blgo示例:
'cscript baidublogbak.vbs myvbscript 0 3 url.htm myvbscript mima
'表示從第0頁(yè)備份到第3頁(yè),blog的共有頁(yè)數(shù)打開(kāi)http://hi.baidu.com/用戶(hù)名/blog/index/0就可以看到了。url.htm存放的是目錄列表
'注意的是百度是從0頁(yè)計(jì)數(shù)的
'如果用戶(hù)名和密碼隨便寫(xiě)也可以備份,但是無(wú)法備份私有文檔
'推薦幾頁(yè)幾頁(yè)備份,最好建單獨(dú)一個(gè)目錄將bak.vbs放進(jìn)去,會(huì)在當(dāng)前目錄生成mht文檔。因?yàn)橛械木W(wǎng)絡(luò)原因,有的無(wú)法成mht,請(qǐng)對(duì)照url.htm目錄列表檢查
'====================================================================================================
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 "正保存第"&n&"頁(yè)"
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,"瀏覽",-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
'cscript bak.vbs 百度用戶(hù)名 第I頁(yè) 至第n頁(yè) 目錄列表.htm 用戶(hù)名 密碼
'例如我的blgo示例:
'cscript baidublogbak.vbs myvbscript 0 3 url.htm myvbscript mima
'表示從第0頁(yè)備份到第3頁(yè),blog的共有頁(yè)數(shù)打開(kāi)http://hi.baidu.com/用戶(hù)名/blog/index/0就可以看到了。url.htm存放的是目錄列表
'注意的是百度是從0頁(yè)計(jì)數(shù)的
'如果用戶(hù)名和密碼隨便寫(xiě)也可以備份,但是無(wú)法備份私有文檔
'推薦幾頁(yè)幾頁(yè)備份,最好建單獨(dú)一個(gè)目錄將bak.vbs放進(jìn)去,會(huì)在當(dāng)前目錄生成mht文檔。因?yàn)橛械木W(wǎng)絡(luò)原因,有的無(wú)法成mht,請(qǐng)對(duì)照url.htm目錄列表檢查
'====================================================================================================
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 "正保存第"&n&"頁(yè)"
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,"瀏覽",-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
相關(guān)文章
VBS ArrayList Class vbs中的數(shù)組類(lèi)
VBS ArrayList Class vbs中的數(shù)組類(lèi)...2007-03-03
使用腳本調(diào)用系統(tǒng)的關(guān)機(jī)對(duì)話(huà)框?qū)崿F(xiàn)代碼
以前有介紹如何使用命令行調(diào)用系統(tǒng)的關(guān)機(jī)對(duì)話(huà)框rundll32.exe shell32.dll #60,但是,上述方法會(huì)存在一問(wèn)題,XP下無(wú)法正常使用該方法進(jìn)行關(guān)機(jī)2012-05-05
vbs 函數(shù) 獲取數(shù)組字符串的最后一個(gè)LastOne 挺方便的
其實(shí)在實(shí)際應(yīng)用中多用 數(shù)組實(shí)現(xiàn),這樣的效率對(duì)于大量的字符串來(lái)說(shuō),效率有點(diǎn)低了。2009-10-10

