百度空间备份脚本baidublogbak.vbs代码分析
程序员文章站
2022-07-04 17:16:58
'用法示例: 'cscript bak.vbs 百度用户名 第i页 至第n页 目录列表.htm 用户名 密码 '例如我的blgo示例: 'cscript baidublog...
'用法示例:
'cscript bak.vbs 百度用户名 第i页 至第n页 目录列表.htm 用户名 密码
'例如我的blgo示例:
'cscript baidublogbak.vbs myvbscript 0 3 url.htm myvbscript mima
'表示从第0页备份到第3页,blog的共有页数打开http://hi.baidu.com/用户名/blog/index/0就可以看到了。url.htm存放的是目录列表
'注意的是百度是从0页计数的
'如果用户名和密码随便写也可以备份,但是无法备份私有文档
'推荐几页几页备份,最好建单独一个目录将bak.vbs放进去,会在当前目录生成mht文档。因为有的网络原因,有的无法成mht,请对照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&"页"
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 百度用户名 第i页 至第n页 目录列表.htm 用户名 密码
'例如我的blgo示例:
'cscript baidublogbak.vbs myvbscript 0 3 url.htm myvbscript mima
'表示从第0页备份到第3页,blog的共有页数打开http://hi.baidu.com/用户名/blog/index/0就可以看到了。url.htm存放的是目录列表
'注意的是百度是从0页计数的
'如果用户名和密码随便写也可以备份,但是无法备份私有文档
'推荐几页几页备份,最好建单独一个目录将bak.vbs放进去,会在当前目录生成mht文档。因为有的网络原因,有的无法成mht,请对照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&"页"
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