圆月山庄资源网 Design By www.vgjia.com
import requests
import re
import json
import os

session = requests.session()


def fetch_url(url):
 return session.get(url).content.decode('gbk')


def get_doc_id(url):
 return re.findall('view/(.*).html', url)[0]


def parse_type(content):
 return re.findall(r"docType.*", content)[0]


def parse_title(content):
 return re.findall(r"title.*", content)[0]


def parse_doc(content):
 result = ''
 url_list = re.findall('(https.*"\\\\\\/", "/") for addr in url_list]
 for url in url_list[:-5]:
  content = fetch_url(url)
  y = 0
  txtlists = re.findall('"c":"(.*".*"y":(.*"md5sum":"(.*"', content)[0]
 pn = re.findall('"totalPageNum":"(.*"', content)[0]
 rsign = re.findall('"rsign":"(.*"', content)[0]
 content_url = 'https://wkretype.bdimg.com/retype/text/' + doc_id + '"https://wenku.baidu.com/browse/getbcsurl" + doc_id + "&pn=1&rn=99999&type=ppt"
 content = fetch_url(content_url)
 url_list = re.findall('{"zoom":"(.*","page"', content)
 url_list = [item.replace("\\", '') for item in url_list]
 if not os.path.exists(doc_id):
  os.mkdir(doc_id)
 for index, url in enumerate(url_list):
  content = session.get(url).content
  path = os.path.join(doc_id, str(index) + '.jpg')
  with open(path, 'wb') as f:
   f.write(content)
 print("图片保存在" + doc_id + "文件夹")


def save_file(filename, content):
 with open(filename, 'w', encoding='utf8') as f:
  f.write(content)
  print('已保存为:' + filename)


# test_txt_url = 'https://wenku.baidu.com/view/cbb4af8b783e0912a3162a89.html"__main__":
 main()

爬取结果

python 爬取百度文库并下载(免费文章限定)

以上就是python 爬取百度文库并以下载的详细内容,更多关于python 爬取百度文库的资料请关注其它相关文章!

标签:
python,爬取百度文库,python,下载百度文库

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com