python可以下载百度文库_用python下载百度文库的代码
先去下载一个叫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('
')+len('')
#print sfrom
sbefore=sfrom+data[sfrom:].index('
')
#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可以下载百度文库_用python下载百度文库的代码相关推荐
- python播放音乐同步歌词_使用Python下载歌词并嵌入歌曲文件中的实现代码
使用python扫描本地音乐并下载歌词 这次这个真的是干货哦,昨晚弄了半晚上,,,,从8点吃完饭就开始写,一直到了快12点才弄好,,,新手,伤不起呀.... 先简单的说下吧,百度提供了一个音乐搜索的a ...
- python批量下载bilibili视频_如何批量下载bilibili的视频?
貌似现在 you-get 已经支持批量下载了.通过下面命令就可以批量下载了 you-get --playlist 网址 本来是带这个需求来的,看到 Venchi 的答案,装了 Python3 之后发现 ...
- python如何下载os库_简谈下载安装Python第三方库的三种方法
如何下载安装Python第三方库(注:此文章以Windows的安装环境为前提) 一.利用Python中的pip进行第三方库的下载 首先我们要搞清楚Python中的pip是个什么东东?pip是一个安装和 ...
- python下载清华镜像_【Anaconda下载】Anaconda3清华镜像下载 v5.3.1 最新版-开心电玩...
软件介绍 Anaconda是一个非常好用的python管理软件,它集成了conda和python等大量科学计算分析的包,可以帮助用户快速实现项目环境的配置.用户在使用过程中,还可以根据实际需要安装部分 ...
- python基础知心得总结_【python】基础学习心得总结(一)
本文将简单阐述一些基本的python知识点,大多是本人在学习过程中的心得体会.简单常用的编程概念和思想将不再描述.若有理解错误,还望指正. 一.python运行,调试 python和相关软件可以在官网 ...
- python需要安装的库_使用python学习【机器学习】需要安装的库~
---------------------------------------------------------------------------------------------------- ...
- python交互式和文件式_使用Python创建和自动化交互式仪表盘
python交互式和文件式 In this tutorial, I will be creating an automated, interactive dashboard of Texas COVI ...
- python做审计底稿视频_最新Python教学视频,每天自学俩小时,让你offer拿到手软...
2020最新Python零基础到精通资料教材,干货分享,新基础Python教材,看这里,这里有你想要的所有资源哦,最强笔记,教你怎么入门提升!让你对自己更加有信心,重点是资料都是免费的,免费!!! 如 ...
- python环境配置及参数_搭建python机器学习环境以及一个机器学习例子
这篇文章介绍了Python机器学习环境的搭建,我用的机器学习开源工具是scikit-learn.下面具体介绍环境搭建以及遇到的一些问题.所有可能需要的软件都可在官网下载,或者在我的百度网盘下载:htt ...
- 学python的有哪些好书_学习python有哪些好书和学习方法?
不请自来~ 上干货 <Python数据分析>作者: [印尼]Ivan Idris Python是一种多范型编程语言,既适用于面向对象的应用开发,又适合函数式设计模式.Python已经成为数 ...
最新文章
- ECC椭圆曲线算法(2)初步介绍
- Github项目解析(九)--实现Activity跳转动画的五种方式
- cacti安装和第三方模块的导入
- 控制台程序console输入参数 获取参数
- quill鼠标悬浮 出现提示_外设报道——DELUX多彩M618X垂直鼠标颠覆创新
- Boring Homework 二叉搜索树的打印,模拟
- oracle19c监听服务启动失败,Oracle19c安装(有失败成功记录)
- SVN 冲突文件详解
- [转载] 五、字符串类的实现及子串查找算法
- windows怎么远程关linux系统,从windows远程关闭linux、windows系统.doc
- JTT808、JTT809、JTT796、JTT794、JTT1077、JTT1078区别与交通部道路运输车辆卫星定位系统部标标准大全下载地址...
- excel计算机求和函数,多条件求和、多条件计数、多条件查找……多了去了!
- RGB三通道图像和灰度值简单理解
- rxJava中 Subscriber 与Observer
- 正则表达式:JAVA正则表达式运用
- 网站草图布局的设计思路SEO
- 多网聚合路由系统打通“融媒体”5G丝绸之路
- 使用SSH协议搭建隧道(附搭建环境超详细)
- 如何处理接口幂等性问题(重复提交)
- 正弦值、余弦值和正切值
热门文章
- 嵌入式BI助力ISV厂商决胜大数据时代
- Matlab实用程序--图形应用-三角函数曲线
- 计算机英语词汇输入,常用计算机英语词汇:BIOS
- SQL注入不完全思路与防注入程序
- 手游天涯明月刀服务器维护到几点,天涯明月刀手游 1月21日停服维护 维护更新详解内容介绍...
- 在MySQL中生成随机经度和纬度
- matlab电磁场 有限元,电磁场有限元Matlab解法.pdf
- 浅谈人机工程应用在数字化工艺中的作用
- 软件工程期末考试试题及答案(详细、经典)
- 服务器日志默认存放位置,系统日志和IIS日志存放路径