最近看小说和漫画看的有点上头…
就顺便用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' + link
title = 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 = 1
for imgInfo in json_list:
imgUrl = imgInfo['url']
print(imgUrl)
# 4. 保存数据
img_data = requests.get(url=imgUrl).content
with open(f'中国惊奇先生/{title}/{count}.jpg', mode='wb') as f:
f.write(img_data)
count += 1
break
except:
pass



好啦,文章分享到这里也就结束啦
或者在小破站搜索:Python小圆
对文章有问题的,或者有其他关于python的问题,可以在评论区留言或者私信我哦
觉得我分享的文章不错的话,可以关注一下我,或者给文章点赞(/≧▽≦)/
