神剑山庄资源网 Design By www.hcban.com
先去下载一个叫SWFToImage.dll的东西
再建立一个bat文件,并运行:
复制代码 代码如下:
COPY SWFToImage.dll %windir%\system32
regsvr32 %windir%\system32\SWFToImage.dll
复制代码 代码如下:
#用python下载百度文库的代码,需要的同志请修改,下面有提示
#http://www.cnblogs.com/dearplain/
#code by plain
import urllib2
import win32com.client
import os
import sys
if __name__=='__main__':
#os.system('');
os.chdir('D:\my project\pywenku')#保存到哪个文件夹
SWFToImage=win32com.client.Dispatch("{479A1AAC-C148-40BB-9868-A9773DA66AF9}");
'''
allfile=os.listdir(".")
findrecord=0
for file in allfile:
if file==".record":
record=open(file,'rw')
findrecord=1
break
if findrecord==0:
record=open('.record','w')
'''
#url="http://wenku.baidu.com/view/8d3ed840be1e650e52ea9938.html?from=rec&pos=1&weight=2&lastweight=2&count=5"
#url="http://wenku.baidu.com/view/f2fe7a3987c24028915fc37a.html?from=related&hasrec=1"
#url就是你要下载的文档的地址
url=sys.argv[1]
if url.find("http://")!=0:
print "error! the url is not correct"
sys.exit()
print "downloading %s"%url
try:
urlReferer=url[url.index('http'):url.index('/v')]
print urlReferer
#urlbody=url[url.index('/v')-1:]
urlnum=url[url.index('ew/')+3:url.index('.htm')]
except ValueError:
print "parse url error"
sys.exit()
#print urlnum
wenku='wenku.baidu.com'
reurl='/play/'
pagefrom='?pn='
downnum='&rn='
#try to get title and make dir
req=urllib2.Request(url)
res=urllib2.urlopen(req)
data=res.read()
try:
sfrom=data.index('<title>')+len('<title>')
#print sfrom
sbefore=sfrom+data[sfrom:].index('</title>')
#print sbefore
title=data[sfrom:sbefore]
title=title[:title.rindex('_')]
print 'downloading '+title
except ValueError:
print "get title error"
sys.exit()
allfile=os.listdir(".")
if (title in allfile)==False:
os.mkdir(title)
os.chdir('./'+title)
#get the first swf
req=urllib2.Request('http://wenku.baidu.com'+reurl+urlnum+pagefrom+'1'+downnum+'1')
req.add_header("Referer", urlReferer )
res=urllib2.urlopen(req)
data=res.read()
res.close()
head=data[0:45]
pagenum=0
sfrom=head.index('\":\"')+len('\":\"')
sbefore=sfrom+head[sfrom:].index('\"')
pagenum=int(head[sfrom:sbefore])
print 'pagenum:'+str(pagenum)
if pagenum<=0 or pagenum>2000:
print "error!!!pagenum<0 or pagenum>2000"
sys.exit()
data=data[106:]
swf=open("1.pywenku",'wb')
swf.write(data)
swf.close()
i=1
SWFToImage.InputSWFFileName="%d.pywenku"%i
SWFToImage.ImageOutputType = 1
SWFToImage.ImageWidth=1048
SWFToImage.ImageHeight=1478
SWFToImage.Execute_Begin()
SWFToImage.FrameIndex = 1
SWFToImage.Execute_GetImage()
SWFToImage.SaveToFile("%d.jpg"%i)
SWFToImage.Execute_End()
os.rename("%d.pywenku"%i,"%d.swf"%i)
allfile=os.listdir(".")
#从第二页下到最后一页
for i in range(2,pagenum+1):
if '%d.swf'%i in allfile:
continue
#not find in the dir mean
req=urllib2.Request('http://wenku.baidu.com'+reurl+urlnum+pagefrom+str(i)+downnum+'1')
res=urllib2.urlopen(req)
data=res.read()
data=data[106:]
swf=open("%d.pywenku"%i,'wb')
swf.write(data)
swf.close()
SWFToImage.InputSWFFileName="%d.pywenku"%i
SWFToImage.ImageOutputType = 1
SWFToImage.Execute_Begin()
SWFToImage.FrameIndex = 1
SWFToImage.Execute_GetImage()
SWFToImage.SaveToFile("%d.jpg"%i)
SWFToImage.Execute_End()
os.rename("%d.pywenku"%i,"%d.swf"%i)
res.close()
print 'task complete'
再建立一个bat文件,并运行:
复制代码 代码如下:
COPY SWFToImage.dll %windir%\system32
regsvr32 %windir%\system32\SWFToImage.dll
复制代码 代码如下:
#用python下载百度文库的代码,需要的同志请修改,下面有提示
#http://www.cnblogs.com/dearplain/
#code by plain
import urllib2
import win32com.client
import os
import sys
if __name__=='__main__':
#os.system('');
os.chdir('D:\my project\pywenku')#保存到哪个文件夹
SWFToImage=win32com.client.Dispatch("{479A1AAC-C148-40BB-9868-A9773DA66AF9}");
'''
allfile=os.listdir(".")
findrecord=0
for file in allfile:
if file==".record":
record=open(file,'rw')
findrecord=1
break
if findrecord==0:
record=open('.record','w')
'''
#url="http://wenku.baidu.com/view/8d3ed840be1e650e52ea9938.html?from=rec&pos=1&weight=2&lastweight=2&count=5"
#url="http://wenku.baidu.com/view/f2fe7a3987c24028915fc37a.html?from=related&hasrec=1"
#url就是你要下载的文档的地址
url=sys.argv[1]
if url.find("http://")!=0:
print "error! the url is not correct"
sys.exit()
print "downloading %s"%url
try:
urlReferer=url[url.index('http'):url.index('/v')]
print urlReferer
#urlbody=url[url.index('/v')-1:]
urlnum=url[url.index('ew/')+3:url.index('.htm')]
except ValueError:
print "parse url error"
sys.exit()
#print urlnum
wenku='wenku.baidu.com'
reurl='/play/'
pagefrom='?pn='
downnum='&rn='
#try to get title and make dir
req=urllib2.Request(url)
res=urllib2.urlopen(req)
data=res.read()
try:
sfrom=data.index('<title>')+len('<title>')
#print sfrom
sbefore=sfrom+data[sfrom:].index('</title>')
#print sbefore
title=data[sfrom:sbefore]
title=title[:title.rindex('_')]
print 'downloading '+title
except ValueError:
print "get title error"
sys.exit()
allfile=os.listdir(".")
if (title in allfile)==False:
os.mkdir(title)
os.chdir('./'+title)
#get the first swf
req=urllib2.Request('http://wenku.baidu.com'+reurl+urlnum+pagefrom+'1'+downnum+'1')
req.add_header("Referer", urlReferer )
res=urllib2.urlopen(req)
data=res.read()
res.close()
head=data[0:45]
pagenum=0
sfrom=head.index('\":\"')+len('\":\"')
sbefore=sfrom+head[sfrom:].index('\"')
pagenum=int(head[sfrom:sbefore])
print 'pagenum:'+str(pagenum)
if pagenum<=0 or pagenum>2000:
print "error!!!pagenum<0 or pagenum>2000"
sys.exit()
data=data[106:]
swf=open("1.pywenku",'wb')
swf.write(data)
swf.close()
i=1
SWFToImage.InputSWFFileName="%d.pywenku"%i
SWFToImage.ImageOutputType = 1
SWFToImage.ImageWidth=1048
SWFToImage.ImageHeight=1478
SWFToImage.Execute_Begin()
SWFToImage.FrameIndex = 1
SWFToImage.Execute_GetImage()
SWFToImage.SaveToFile("%d.jpg"%i)
SWFToImage.Execute_End()
os.rename("%d.pywenku"%i,"%d.swf"%i)
allfile=os.listdir(".")
#从第二页下到最后一页
for i in range(2,pagenum+1):
if '%d.swf'%i in allfile:
continue
#not find in the dir mean
req=urllib2.Request('http://wenku.baidu.com'+reurl+urlnum+pagefrom+str(i)+downnum+'1')
res=urllib2.urlopen(req)
data=res.read()
data=data[106:]
swf=open("%d.pywenku"%i,'wb')
swf.write(data)
swf.close()
SWFToImage.InputSWFFileName="%d.pywenku"%i
SWFToImage.ImageOutputType = 1
SWFToImage.Execute_Begin()
SWFToImage.FrameIndex = 1
SWFToImage.Execute_GetImage()
SWFToImage.SaveToFile("%d.jpg"%i)
SWFToImage.Execute_End()
os.rename("%d.pywenku"%i,"%d.swf"%i)
res.close()
print 'task complete'
标签:
python,百度文库
神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com
暂无用python下载百度文库的代码的评论...
更新日志
2024年10月04日
2024年10月04日
- 孙悦.1996-伙伴【正大国际】【WAV+CUE】
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】