简单的178漫画下载器
自己写的漫画下载器 用来下载178完结漫画 用来保存
用法:把要下载的漫画地址复制到软件点击下载就是了
下完文件在软件目录中
from lxml import etree
import requests
import re
import execjs
import sys
import json
import os
from PIL import Imageclass Spider():def __init__(self, url):self.tempurl = urlself.headers = {'User-Agent':'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1','cookie': 'UM_distinctid=1638b27abaf146-0b1d75740d4133-52693478-13c680-1638b27abb066; show_tip_1=0; CNZZDATA3470106=cnzz_eid%3D320706176-1532649440-https%253A%252F%252Fmanhua.dmzj.com%252F%26ntime%3D1533193311; CNZZDATA1000465408=1196428649-1527042905-https%253A%252F%252Fwww.baidu.com%252F%7C1539671806; CNZZDATA1000465515=1879849850-1527044952-https%253A%252F%252Fwww.baidu.com%252F%7C1539672264; display_mode=1; pt_s_198bb240=vt=1539672637572&cad=; pt_198bb240=uid=axDGwW5njubICm6c4HSMhA&nid=0&vid=M8Z/D4L7pD2pXmKvRYVo0A&vn=17&pvn=2&sact=1539672641787&to_flag=0&pl=J8gHIAMoYA2Eg1lD2m4zWQ*pt*1539672637572; CNZZDATA30043528=cnzz_eid%3D223015019-1533021818-https%253A%252F%252Fmanhua.dmzj.com%252F%26ntime%3D1539667867; CNZZDATA30039253=cnzz_eid%3D1296344247-1533023188-https%253A%252F%252Fmanhua.dmzj.com%252F%26ntime%3D1539671932'}self.zp={}def paseUrl(self,url):r = requests.get(url, headers= self.headers)return r.content.decode('utf-8')# 得到所有漫画的所有话数和所有地址def getManHualink(self,htmlstr):htmlstr = etree.HTML(htmlstr)links = htmlstr.xpath("//div[@class='cartoon_online_border']//li/a/@href")links.append(htmlstr.xpath("//div[@style='display:none']//li/a/@href"))title = htmlstr.xpath("//div[@class='cartoon_online_border']//li/a/@title")manhuatitle = htmlstr.xpath("//span[@class='anim_title_text']/a/h1/text()")[0]return title,links,manhuatitledef getManHualink2(self,htmlstr):htmlstr = etree.HTML(htmlstr)links = htmlstr.xpath("//div[@class='tab-content tab-content-selected zj_list_con autoHeight']//li/a/@href")title = htmlstr.xpath("//div[@class='tab-content tab-content-selected zj_list_con autoHeight']//li/a/@title")manhuatitle = htmlstr.xpath("//div[@class='comic_deCon']/h1/a/text()")[0]return title,links,manhuatitle# 保存漫画def saveFile(self,title,manhuatitle):if(os.path.exists(manhuatitle)==False):os.mkdir(manhuatitle)for t in title:if(os.path.exists(manhuatitle+'\\'+t)==False):os.mkdir("{}\{}".format(manhuatitle,t))new_pic=[]for url in self.zp[t]:pic = requests.get(url, headers=self.headers).contenttname = '.\{}\{}\{}.jpg'.format(manhuatitle,t,self.zp[t].index(url))new_pic.append('{}.jpg'.format(self.zp[t].index(url)))print(tname)with open(tname,'wb') as f:f.write(pic)try:self.savepdf(new_pic,"{}\{}".format(manhuatitle,t),'.\{}\{}.pdf'.format(manhuatitle,t))except Exception:continueelse:passfinally:passprint("保存完毕")def savepdf(self,new_pic,path,pdf_name):im_list = []im1 = Image.open(os.path.join(path, new_pic[0]))new_pic.pop(0)for i in new_pic:img = Image.open(os.path.join(path, i))if img.mode == "RGBA":img = img.convert('RGB')im_list.append(img)else:im_list.append(img)im1.save(pdf_name, "PDF", resolution=100.0, save_all=True, append_images=im_list)print("输出文件名称:", pdf_name)# 解析js 获取漫画图片地址def paseJs(self,url):tempurl = 'https://manhua.dmzj.com{}'.format(url)self.headers['referer'] = tempurlhtmlstr = self.paseUrl(tempurl)jscode =re.findall(r"var page = '';(.*?) var",htmlstr,re.S)[0].strip()jscode+=' function a(){ return pages }'ctx = execjs.compile(jscode)piclist = ctx.call('a')piclist = piclist.split(",")ptemp =[]for p in piclist:s = re.findall(r'\"(.*)\"',p)[0]ptemp.append('https://images.dmzj.com/{}'.format(s))return ptempdef pasejs2(self,url):self.headers['referer'] = urlhtmlstr = self.paseUrl(url)jscode =re.findall(r"var page = '';(.*?)</script>",htmlstr,re.S)[0].strip()jscode+=' function a(){ return pages }'ctx = execjs.compile(jscode)piclist = ctx.call('a')piclist = re.findall(r'"page_url":"(.*?)","sum_pages',piclist,re.S)[0].strip()piclist = piclist.split("\r\n")ptemp =[]for p in piclist:ptemp.append("https://images.dmzj.com/{}".format(p))#print(ptemp)return ptempdef getPicList2(self,links,title):for t in title:self.zp[t] = self.pasejs2(links[title.index(t)])def getPicList(self,links,title):for t in title:self.zp[t] = self.paseJs(links[title.index(t)])def runspider(self):htmlstr = self.paseUrl(self.tempurl)title,links,manhuatitle = self.getManHualink2(htmlstr)self.getPicList2(links,title)self.saveFile(title,manhuatitle)def runspider2(self):# 得到改漫画的所有话数的所有地址htmlstr = self.paseUrl(self.tempurl)title,links,manhuatitle = self.getManHualink(htmlstr)# 获取漫画主页通过js解析出所有图片地址self.getPicList(links,title)#保存漫画self.saveFile(title,manhuatitle)def run(self):print("正在努力地获取漫画图片------请稍等片刻")if re.findall('https://www.dmzj.com/info',self.tempurl):self.runspider()else:self.runspider2()if __name__ == '__main__':link = sys.argv[1]spider = Spider(link)spider.run()
from tkinter import *
from tkinter import ttk
import tkinter.messagebox
from ManHuaSpider import Spider
import webbrowser
import threading
def calcPlus():print('开始下漫画')links =link.get()spide = Spider(links)spide.run()text ='下载漫画完毕'tkinter.messagebox.showinfo('提示',text)def getweb():webbrowser.open("https://manhua.dmzj.com/update_1.shtml")
def getweb1():tkinter.messagebox.showinfo('关于',"本软件不得用于商业用途,仅做学习交流 更多内容请关注微信公众号 每天一游戏")def thread_it():'''将函数打包进线程'''# 创建t = threading.Thread(target=calcPlus) # 守护 !!!t.setDaemon(True) # 启动t.start()if __name__ == '__main__':root = Tk()root.title('178漫画下载器--by 每天一游戏')link = StringVar()lb = tkinter.Listbox()f1 = Frame(root)f1.pack(padx=10,pady=5)Label(f1, text="要下载的漫画链接:").grid(row=0,column=0)f1r = Frame(f1)f1r.grid(row=0, column=1)e1 = Entry(f1r, textvariable=link, width=50).grid(row=0,column=1)Button(f1r, text="下载", command=thread_it).grid(row=0, column=2)Button(f1r, text="打开网站", command=getweb).grid(row=0, column=3)Button(f1r, text="关于", command=getweb1).grid(row=0, column=4)mainloop()