最近看小说和漫画看的有点上头…
就顺便用Python来采集一下漫画吧
随便抓个漫画分享一下,搞清楚思路后,自己多练练就能自己采集想看的漫画咯
import base64
import requests
import re
import json
import parsel
import os
# 伪装
headers = {# 用户信息'cookie': '__AC__=1; tvf....
源码.资料.素材.点击领取即可
select = parsel.Selector(requests.get(main_url, headers=headers).text)
title_list = select.css('.chapter-page-all.works-chapter-list li a::text').getall()
link_list = select.css('.chapter-page-all.works-chapter-list li a::attr(href)').getall()for title, link in zip(title_list, link_list):url = 'https://ac.qq.com' + linktitle = title.strip()if not os.path.exists(f'中国惊奇先生/{title}'):os.makedirs(f'中国惊奇先生/{title}')# 1. 发送请求response = requests.get(url=url, headers=headers)print(title, url)# 2. 获取数据html_data = response.text# 3. 解析数据DATA = re.findall("var DATA = '(.*?)'", html_data)[0]for i in range(len(DATA)):try:json_str = base64.b64decode(DATA[i:].encode("utf-8")).decode("utf-8")json_str = re.findall('"picture":(\[.*?\])', json_str)[0]# 字符串 转 字典/列表json_list = json.loads(json_str)count = 1for imgInfo in json_list:imgUrl = imgInfo['url']print(imgUrl)# 4. 保存数据img_data = requests.get(url=imgUrl).contentwith open(f'中国惊奇先生/{title}/{count}.jpg', mode='wb') as f:f.write(img_data)count += 1breakexcept:pass
好啦,文章分享到这里也就结束啦
想用视频学习Python的可以点击此处~
或者在小破站搜索:Python小圆
对文章有问题的,或者有其他关于python的问题,可以在评论区留言或者私信我哦
觉得我分享的文章不错的话,可以关注一下我,或者给文章点赞(/≧▽≦)/