开通《金牌VIP》,全站所有资源均可免积分下载!

Python实现百度文库下载

广告位2

from clipboard
#!/usr/bin/python2.7#coding=utf-8import re;import urllib;import urllib.request; header = { "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 UBrowser/1.0.370.1388 Safari/537.36", } URL_GETBDWKDOC = "http://wenku.baidu.com/play/{0}?pn={1}";URL_BDWK = "http://wenku.baidu.com/view/{0}.html"; class BdWkDownloader: def __init__(self): pass; def getTotalPages(self, id): return int(re.compile(r"totalPageNum'\s*:\s*'(\d )'").findall(urllib.request.urlopen(URL_BDWK.format(id)).read().decode("gb2312"))[0]); def download(self, id, dir = "./"): num = self.getTotalPages(id); for i in range(0, num): request = urllib.request.Request(URL_GETBDWKDOC.format(id, i 1), headers = header); data = urllib.request.urlopen(request).read(); file = open("{0}{1}.{2}".format(dir, i, "swf"), "wb"); file.write(data[106:]); file.close(); def main(): downloader = BdWkDownloader(); downloader.download("ef13d84ea6c30c2259019e5b"); if(__name__ == "__main__"): main();

转载请注明出处:https://www.5t6t.com/97847.htm
相关推荐:下载/源码例子/百度

评论(1)

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !

在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复