時間:2023-07-23 00:00:02 | 來源:網(wǎng)站運營
時間:2023-07-23 00:00:02 來源:網(wǎng)站運營
原來制作一個漫畫網(wǎng)站這么簡單!!!!!: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']}" # 判斷目錄是否存在,不存在則創(chuàng)建目錄 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: # 判斷目錄是否存在,不存在則創(chuàng)建目錄 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}已經(jīng)下載完成,即將下載{next_chapter_name},chapter_newid為{chapter_newid}") else: breakif __name__ == '__main__': saveComic(False)
關(guān)鍵詞:簡單,漫畫
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。