特别说明:

因为早些时候鼠绘的接口调整,之前的代码已经不能用了。

正好最近在学习scrapy,于是重新写了一个,项目放在github  https://github.com/TurboWay/ishuhui

一、起因:

  很喜欢看海贼漫画,其中鼠绘汉化的海贼王无疑是最好的,更新最快的。但是由于版权的问题,迫于压力,鼠绘官网早一点的海贼王已经看不了,但是。。。重点是,我发现接口还是可以用的,于是就写了个爬虫把鼠绘翻译的海贼王漫画都爬了下来。分享下源码,供有需要的海迷使用。另外建议不要在高峰时段爬取,毕竟我们都爱鼠绘。

二、如何使用:

  有安装python环境的,直接复制源码,运行.py

三、代码如下:

# -*- coding: utf-8 -*-
import requests,json,time,os,shutil,logging,sys
from PIL import Image
from io import BytesIO logger = logging.getLogger('log')
logger.setLevel(logging.DEBUG) # log format
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') # console log
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch) def get_url(url):
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)'
' Chrome/62.0.3202.75 Safari/537.36'}
response = requests.get(url=url, headers=headers, timeout=5)
js = json.loads(response.text)
if js["errNo"] == 0:
return js["data"]
else:
logger.warning("请求失败:{0}".format(js)) # 去掉文件名禁止符号
def clean(text):
kws = ['/','\\',':','*','"','<','>','|','?']
for kw in kws:
text = text.replace(kw,'.')
return text # 新建文件夹
def makefile(path,istruncate):
if os.path.exists(path) and istruncate:
shutil.rmtree(path)
os.mkdir(path)
elif not os.path.exists(path):
os.mkdir(path) # 下载图片
def save_pic(img_src,picname):
try:
response = requests.get(img_src)
image = Image.open(BytesIO(response.content))
image = image.convert('RGB')
image.save(picname)
logger.info("{0}图片下载成功".format(picname))
flag = True
except Exception as e:
logger.info("{0}图片下载失败:{1}".format(picname,e))
flag = False
return flag # 保存图片
def resave_pic(img_src,picname):
count,flag = 0,save_pic(img_src,picname)
while not flag:
flag = save_pic(img_src, picname)
count += 1
if count > 5:
break def get_data(path,nextid):
url = 'http://hhzapi.ishuhui.com/cartoon/post/ver/76906890/id/{0}.json'.format(nextid)
data = get_url(url)
if data:
server = 'http://pic04.ishuhui.com/'
source, id, title, book, number = data['source'], data['id'], data['title'], data['book_text'], data['number']
content_img = eval(data['content_img']) if data['content_img'] else {}
if source == 1: # 鼠绘汉化
makefile(path + '\\' + book, False)
title = clean(title)
filepath = path + '\{0}\{0} 第 {1} 话 {2}'.format(book,number,title)
makefile(filepath, True) # 新建文件夹
if content_img: # 下载图片
for img, imgurl in content_img.items():
imgurl = server + imgurl.replace('/upload/','')
picname = filepath + '\\'+ img
resave_pic(imgurl,picname)
logger.info("ID:{2} 第 {0} 话 {1}下载完成".format(number,title,id))
next = data['prev']
if next:
return next['id']
elif nextid == 900: # 900的时候会找不到上一页
return 899 if __name__ == "__main__":
path=sys.path[0]
nextid=get_data(path,10881)
while nextid:
nextid=get_data(path,nextid)
time.sleep(3)

四、结果如下:

  第598话 2年后 -- 第908话 世界會議開幕,共309话,3.22G,其中680和681话缺失了,接口扫了一下也没找到。

【python3】爬取鼠绘汉化的海贼王漫画的更多相关文章

  1. scrapy 动态网页处理——爬取鼠绘海贼王最新漫画

    简介 scrapy是基于python的爬虫框架,易于学习与使用.本篇文章主要介绍如何使用scrapy爬取鼠绘漫画网海贼王最新一集的漫画. 源码参见:https://github.com/liudaol ...

  2. python3爬取网页

    爬虫 python3爬取网页资源方式(1.最简单: import'http://www.baidu.com/'print2.通过request import'http://www.baidu.com' ...

  3. python3爬取女神图片,破解盗链问题

    title: python3爬取女神图片,破解盗链问题 date: 2018-04-22 08:26:00 tags: [python3,美女,图片抓取,爬虫, 盗链] comments: true ...

  4. Python3 爬取微信好友基本信息,并进行数据清洗

    Python3 爬取微信好友基本信息,并进行数据清洗 1,登录获取好友基础信息: 好友的获取方法为get_friends,将会返回完整的好友列表. 其中每个好友为一个字典 列表的第一项为本人的账号信息 ...

  5. Python3爬取人人网(校内网)个人照片及朋友照片,并一键下载到本地~~~附源代码

    题记: 11月14日早晨8点,人人网发布公告,宣布人人公司将人人网社交平台业务相关资产以2000万美元的现金加4000万美元的股票对价出售予北京多牛传媒,自此,人人公司将专注于境内的二手车业务和在美国 ...

  6. python3爬取微博评论并存为xlsx

    python3爬取微博评论并存为xlsx**由于微博电脑端的网页版页面比较复杂,我们可以访问手机端的微博网站,网址为:https://m.weibo.cn/一.访问微博网站,找到热门推荐链接我们打开微 ...

  7. python3爬取全民K歌

    Python3爬取全民k歌 环境 python3.5 + requests 1.通过歌曲主页链接爬取 首先打开歌曲主页,打开开发者工具(F12). 选择Network,点击播放,会发现有一个请求返回的 ...

  8. Python3爬取猫眼电影信息

    Python3爬取猫眼电影信息 import json import requests from requests.exceptions import RequestException import ...

  9. 利用python3 爬取 网易云 上 周杰伦所有专辑,歌曲,评论,并完成可视化分析已经歌曲情绪化分析

    这篇文章适合于python爱好者,里面可能很多语句是冗长的,甚至可能有一些尚未发现的BUG,这个伴随着我们继续学习来慢慢消解吧.接下来 我把里面会用到的东西在这里做一个简单总结吧:本文用到了两门解释性 ...

随机推荐

  1. Common administrative commands in Red Hat Enterprise Linux 5, 6, and 7

    https://access.redhat.com/articles/1189123 Common administrative commands in Red Hat Enterprise Linu ...

  2. KHFlatButton

    KHFlatButton https://github.com/kylehorn/KHFlatButton 效果: 对于自己做demo来说,每次设置button就不用这么折腾了,几句话就行了,非常爽: ...

  3. Linux 系统的DNS配置文件

    系统的DNS配置文件 方式一: 界面操作 setup -->界面配置网络,网关等 方式二: 修改配置文件 # 修改配置 ==>vi /etc/resolv.conf -->man r ...

  4. oracle 28001错误 密码过期失效

    背景 服务器演示地址,无法使用.排查原因,是数据库密码有问题,报28001错误 问题 确定是oracle密码机制,180失效了 解决 1.进入sqlplus模式 sqlplus / as sysdba ...

  5. TreeMap:是基于红黑树的Map接口的实现

    > TreeMap:是基于红黑树的Map接口的实现. 红黑树:平衡二叉树 取出时,可以有三种方式:前序遍历,中序遍历,后序遍历 >排序: A 自然排序  --TreeMap无参构造 Tre ...

  6. K8S Deployment 命令

    创建 Deployment kubectl create -f https://kubernetes.io/docs/user-guide/nginx-deployment.yaml --record ...

  7. 【原创】Python 对象创建过程中元类, __new__, __call__, __init__ 的处理

    原始type: type是最原始的元类,其__call__方法是在你使用" t_class = type(classname_string, base_classes_tuple, attr ...

  8. 【原创】由于python的导入方式引起的深坑

    目录结构: test/ sacc/ __init__.py app.py logger.py /views __init__.py main.py 事情是这样的,logger里面是一个类LoggerF ...

  9. ARC与Toll-Free Bridging

    arc模块与mrc模块的沟通. 相当于程序的混编处理. Toll-Free Briding保证了在程序中,可以方便和谐的使用Core Foundation类型的对象和Objective-C类型的对象. ...

  10. Golang context包解读

    Context 通常被译作 上下文 ,一般理解为程序单元的一个运行状态.现场.快照,而翻译中 上下 又很好地诠释了其本质,上下上下则是存在上下层的传递, 上 会把内容传递给 下 . 在Go语言中,程序 ...