漫画网站通常都不能通过右键来查看网页源代码和检查,所以我们需要通过快捷方式来查看,我用的是Mac快捷键是,查看网页源码command+option+u、检查F12
首先我们打开检查,可以看到加载的图片链接
找到这个标签的id进行全局搜索
打开这个文件大概看一下我们就可以发现是通过一个ajax get请求获取的图片链接
可以看到data里需要携带几个参数,这几个参数实际上在网页源码里有返回
通过抓包我们抓到这个请求
返回内容
执行一下这个返回的就是当前章节的所有图片
下面直接上代码
import re
import execjs
import requests
import urllib.parse
class Mangabz:
"""
日本漫画漫画章节图片下载
"""
def __init__(self, url):
self.url = url
self.session = requests.Session()
self.headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
"Referer": self.url,
"Cookie": "image_time_cookie=17115|637270678077155170|2",
}
def get_chapter_argv(self):
res = requests.get(self.url, headers=self.headers, timeout=10)
mangabz_cid = re.findall("MANGABZ_CID=(.*?);", res.text)[0]
mangabz_mid = re.findall("MANGABZ_MID=(.*?);", res.text)[0]
page_total = re.findall("MANGABZ_IMAGE_COUNT=(.*?);", res.text)[0]
mangabz_viewsign_dt = re.findall("MANGABZ_VIEWSIGN_DT=\"(.*?)\";", res.text)[0]
mangabz_viewsign = re.findall("MANGABZ_VIEWSIGN=\"(.*?)\";", res.text)[0]
return (mangabz_cid, mangabz_mid, mangabz_viewsign_dt, mangabz_viewsign, page_total)
def get_images_js(self, page, mangabz_cid, mangabz_mid, mangabz_viewsign_dt, mangabz_viewsign):
url = self.url + "chapterimage.ashx?" + "cid=%s&page=%s&key=&_cid=%s&_mid=%s&_dt=%s&_sign=%s" % (mangabz_cid, page, mangabz_cid, mangabz_mid, urllib.parse.quote(mangabz_viewsign_dt), mangabz_viewsign)
res = self.session.get(url, headers=self.headers, timeout=10)
self.headers["Referer"] = res.url
return res.text
def run(self):
mangabz_cid, mangabz_mid, mangabz_viewsign_dt, mangabz_viewsign, page_total = self.get_chapter_argv()
for i in range(int(page_total)):
i += 1
js_str = self.get_images_js(i, mangabz_cid, mangabz_mid, mangabz_viewsign_dt, mangabz_viewsign)
imagesList = execjs.eval(js_str)
print(imagesList[0])
if __name__ == '__main__':
mangabz = Mangabz("http://www.mangabz.com/m17115/")
mangabz.run()
"""
result:
http://image.mangabz.com/1/249/17115/1_9913.jpg?cid=17115&key=16f4cd6d4bc919191eb29b37a2bcf872&uk=
http://image.mangabz.com/1/249/17115/2_3245.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/3_6479.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/4_5401.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/5_3441.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/6_9421.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/7_3221.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/8_3533.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/9_4780.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/10_2250.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/11_3742.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/12_6481.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/13_4772.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/14_1675.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/15_1266.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/16_9599.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/17_4840.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/18_5913.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/19_1302.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/20_6355.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/21_3462.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/22_6553.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
http://image.mangabz.com/1/249/17115/23_5102.jpg?cid=17115&key=eb6e23a95153bbd5efe6ca81ea3016f6&uk=
关于图片下载可以看我其他的爬虫文章
"""