时间:2023-07-23 00:00:02 | 来源:网站运营
时间:2023-07-23 00:00:02 来源:网站运营
原来制作一个漫画网站这么简单!!!!!:import osimport requestsfrom PIL import Imagefrom io import BytesIOdef MergeImage(width, height, imgList, save_img): # -----create a new image-----# img = Image.new("RGB", (width, height), (0, 0, 0)) h = 0 for iimg in imgList: img.paste(iimg, (0, h)) h += iimg.size[1] img.save(save_img) print("保存成功")def saveComic(splitComic): headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.53", "Referer": "https://www.manhuatai.com/", "Accept": "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8", } chapter_newid = "dyhzs" while True: params = { "product_id": 2, "productname": "mht", "platformname": "pc", "comic_id": 27417, "chapter_newid": chapter_newid, "isWebp": 1, "quality": "middle" } url = "https://www.manhuatai.com/api/getchapterinfov2" # 请求漫画api resp = requests.get(url=url, params=params, headers=headers).json() # 获取标题 chapter_name = resp['data']['current_chapter']['chapter_name'] # 获取当前话的图片列表 chapter_img_list = resp['data']['current_chapter']['chapter_img_list'] # 获取目录名 dirName = f"./result/{resp['data']['comic_name']}" # 判断目录是否存在,不存在则创建目录 if not os.path.exists(dirName): os.mkdir(dirName) index = 1 imgList = [] maxWidth = 0 height = 0 for imgUrl in chapter_img_list: content = requests.get(url=imgUrl, headers=headers).content if not splitComic: # 直接将分开的图片合并在一起 bytes_stream = BytesIO(content) image = Image.open(bytes_stream) imgList.append(image) maxWidth = max(maxWidth, image.size[0]) height += image.size[1] else: # 判断目录是否存在,不存在则创建目录 if not os.path.exists(dirName+"/"+chapter_name): os.mkdir(dirName+"/"+chapter_name) with open(f"{dirName}/{chapter_name}/{chapter_name}{index}.webp",mode="wb") as fs: fs.write(content) index += 1 if not splitComic: MergeImage(maxWidth, height, imgList, f"{dirName}/{chapter_name}.png") # 最后一话直接跳出 if resp['data']['next_chapter']: # 获取下一话的chapter_newid chapter_newid = resp['data']['next_chapter']['chapter_newid'] next_chapter_name = resp['data']['next_chapter']['chapter_name'] print(f"{chapter_name}已经下载完成,即将下载{next_chapter_name},chapter_newid为{chapter_newid}") else: breakif __name__ == '__main__': saveComic(False)
关键词:简单,漫画