下载漫画
作者:互联网
1 import os 2 import requests 3 from tkinter import * 4 import tkinter.messagebox 5 from openpyxl import load_workbook 6 from tkinter import ttk 7 import pprint 8 from tkinter import Tk, Checkbutton, Label 9 from tkinter import StringVar, IntVar 10 from urllib.parse import quote 11 aaa='漫画名称.xlsx' 12 addr=os.path.join(os.path.dirname(os.path.abspath(__file__)),aaa) 13 wb = load_workbook(addr) 14 sheet = wb["漫画名称"] 15 row_max = sheet.max_row 16 漫画集合 = [] 17 for i in range(2, row_max+1, 1): 18 漫画名称 = sheet.cell(i, 1).value 19 漫画ID = sheet.cell(i, 2).value 20 漫画集合.append([漫画名称, 漫画ID]) 21 url="http://api.iheyman.com/api/cartoon/sectionInfo" 22 data="bid={0}&msgId={1}&autoPay=0&token=7dd4591f07fb32f9aee4b196388edfc8&meid=228788&system=android&youngBoys=2&identifier=1603375879&version=304&channelId=1021619&checksum=5da54c5b4c1b5d2b6d931fcd96f7a600" 23 headers={ 24 "Content-Type": "application/x-www-form-urlencoded", 25 "user-agent": "VOG-AL00(Android/7.1.2) (heyman.iseymon.com/3.0.4) Weex/0.26.0 720x1280", 26 "Host": "api.iheyman.com", 27 "Connection": "Keep-Alive", 28 "Accept-Encoding": "gzip", 29 "Content-Length": "199" 30 } 31 headers2={ 32 "Content-Type": "application/x-www-form-urlencoded", 33 "user-agent": "VOG-AL00(Android/7.1.2) (heyman.iseymon.com/3.0.4) Weex/0.26.0 720x1280", 34 "Host": "api.iheyman.com", 35 "Connection": "Keep-Alive", 36 "Accept-Encoding": "gzip", 37 "Content-Length": "178" 38 } 39 url2="http://api.iheyman.com/api/cartoon/newRank" 40 data2="type={}&token=7dd4591f07fb32f9aee4b196388edfc8&meid=228788&system=android&youngBoys=2&identifier=1603513026&version=304&channelId=1021619&checksum=c98b4056551d1367be13bff335d1a825" 41 url3 = "http://api.iheyman.com/api/cartoon/lists" 42 headers3 = { 43 "Content-Type": "application/x-www-form-urlencoded", 44 "user-agent": "VOG-AL00(Android/7.1.2) (heyman.iseymon.com/3.0.4) Weex/0.26.0 720x1280", 45 "Host": "api.iheyman.com", 46 "Connection": "Keep-Alive", 47 "Accept-Encoding": "gzip", 48 "Content-Length": "208" 49 } 50 data3 = "page=1&tabIndex=1&keysword={}&token=7dd4591f07fb32f9aee4b196388edfc8&meid=228788&system=android&youngBoys=2&identifier=1603545674&version=304&channelId=1021619&checksum=cb548380ea9ff68b58aaa9757987392a" 51 52 53 def 排行(a): 54 list_1 = [] 55 reponse=requests.post(url2,data=data2.format(a),headers=headers2) 56 for i in range(len(reponse.json()["data"]["list"])): 57 title=reponse.json()["data"]["list"][i]['title'] 58 bid=reponse.json()["data"]["list"][i]["bid"] 59 sectionNum = reponse.json()["data"]["list"][i]["sectionNum"] 60 list_1.append([bid,title,sectionNum+"话"]) 61 62 com2["value"] = list_1 63 def bbb(): # 下载要的图片 64 a = int(E1.get()) 65 b = int(E2.get()) + 1 66 # c="28061" 67 # print(com2.get()) 68 # print(com2.get().replace(") "," ").replace(" (","").replace(" )","").replace("( ","").replace("{ ","").replace("} "," ").replace("/","").replace("}","").replace("}","")) 69 c = com2.get().split()[0] 70 # print(c) 71 d = com2.get().split()[1] 72 73 num = 0 74 for i in range(a, b): # 包括前不包括后 75 # c="28061" 76 c = c 77 da = requests.post(url, data=data.format(c, i), headers=headers2) 78 79 80 html = da.json() 81 82 url_list = html["data"]["list"] 83 84 n = 0 85 for img_url in url_list: 86 # img_url = "http://app.cdn.a2.dhcwy.com/webroot/cartoon/28061/5c255ae3e7bca5c83a2ebf3beb14007d.jpg?v=2.0" 87 img_url = img_url 88 n += 1 89 num += 1 90 91 download_img2(img_url, i, n) 92 93 text.set('下载结束,共下载{}话,一共{}张'.format(b - a, num)) 94 tkinter.messagebox.showinfo('提示', '{}第{}-{}话已下载完成'.format(d, a, b - 1)) 95 def download_img(img_url,i,n): 96 # print (img_url) 97 98 # header = {"Authorization": "Bearer " + api_token} # 设置http header,视情况加需要的条目,这里的token是用来鉴权的一种方式 99 r = requests.get(img_url) 100 # print(r.status_code) # 返回状态码 101 if r.status_code == 200: 102 103 name_mh = com.get().split()[0] 104 start_mh = int(E1.get()) 105 end_mh = int(E2.get()) 106 new_name="{}{}-{}".format(name_mh,start_mh,end_mh) 107 dir_mh = os.path.join(os.path.dirname(os.path.abspath(__file__)), new_name) 108 isExists = os.path.exists(dir_mh) 109 # 判断结果 110 if not isExists: 111 # 如果不存在则创建目录 112 # 创建目录操作函数 113 os.makedirs(dir_mh) 114 open('{}//{}-{}.png'.format(dir_mh,i,n), 'wb').write(r.content) # 将内容写入图片 115 116 del r 117 def download_img2(img_url,i,n): 118 119 120 # header = {"Authorization": "Bearer " + api_token} # 设置http header,视情况加需要的条目,这里的token是用来鉴权的一种方式 121 r = requests.get(img_url) 122 123 if r.status_code == 200: 124 125 name_mh =com2.get().replace(") "," ").replace(" (","").replace(" )","").replace("( ","").replace("{ ","").replace("} "," ").replace("/","").replace("}","").replace("{","").replace(")","").replace(")","").split()[1] 126 127 start_mh = int(E1.get()) 128 end_mh = int(E2.get()) 129 new_name="{}{}-{}".format(name_mh,start_mh,end_mh) 130 dir_mh = os.path.join(os.path.dirname(os.path.abspath(__file__)), new_name) 131 isExists = os.path.exists(dir_mh) 132 # 判断结果 133 if not isExists: 134 # 如果不存在则创建目录 135 # 创建目录操作函数 136 os.makedirs(dir_mh) 137 open('{}//{}-{}.png'.format(dir_mh,i,n), 'wb').write(r.content) # 将内容写入图片 138 # print("done") 139 del r 140 def aaa(): # 下载要的图片 141 a=int(E1.get()) 142 b=int(E2.get())+1 143 # c="28061" 144 c=com.get().split( )[1] 145 d=com.get().split( )[0] 146 147 num=0 148 for i in range(a, b): #包括前不包括后 149 # c="28061" 150 c=c 151 da = requests.post(url, data=data.format(c,i), headers=headers) 152 print("下载") 153 html = da.json() 154 url_list = html["data"]["list"] 155 n=0 156 for img_url in url_list: 157 # img_url = "http://app.cdn.a2.dhcwy.com/webroot/cartoon/28061/5c255ae3e7bca5c83a2ebf3beb14007d.jpg?v=2.0" 158 img_url =img_url 159 n+=1 160 num+=1 161 download_img(img_url,i,n) 162 text.set('下载结束,共下载{}话,一共{}张'.format(b - a, num)) 163 tkinter.messagebox.showinfo('提示','{}第{}-{}话已下载完成'.format(d,a,b-1)) 164 def 搜索(): 165 list2=[] 166 key=E3.get() 167 reposen = requests.post(url=url3, data=data3.format(quote(key)), headers=headers3) 168 # pprint.pprint(reposen.json()["data"]["infoList"]) 169 for i in range(len(reposen.json()["data"]["infoList"])): 170 # print(reposen.json()["data"]["infoList"][i]['title']) 171 # print(reposen.json()["data"]["infoList"][i]['bid']) 172 # print(reposen.json()["data"]["infoList"][i]["sectionNum"]) 173 title = reposen.json()["data"]["infoList"][i]['title'] 174 bid = reposen.json()["data"]["infoList"][i]['bid'] 175 sectionNum = reposen.json()["data"]["infoList"][i]["sectionNum"] 176 list2.append([bid,title,sectionNum+"话"]) 177 com2["value"]=list2 178 root=Tk() 179 root.title("下载by斌") 180 cv= tkinter.StringVar() 181 com=ttk.Combobox(root,textvariable=cv) 182 # com.grid() 183 # E3 = Entry(root, bd =5) 184 com.grid(row=2,column=1,sticky=W) 185 #设置下拉数据 186 com["value"]=漫画集合 187 lable1 = Label(root,text='输入开始话:') 188 lable1.grid(row=0,column=0) 189 E1 = Entry(root, bd =5) 190 E1.grid(row=0,column=1,sticky=W) 191 lable2 = Label(root,text='输入结束话:') 192 lable2.grid(row=1,column=0) 193 E2 = Entry(root, bd =5) 194 E2.grid(row=1,column=1,sticky=W) 195 lable3 = Label(root,text='输选择漫画ID:') 196 lable3.grid(row=2,column=0) 197 text = StringVar() 198 # but2=Button(root,text='确定',font=('KaiTi',28,'bold'),bg='red',fg='green',width=15,command=lambda : aaa(a=1, b=2, c="28061")) 199 but2=Button(root,text='开始下载1',font=('KaiTi',13,'bold'),bg='red',fg='green',width=10,command=aaa) 200 but3=Button(root,text='综合榜',command=lambda : 排行(a=0)) 201 but4=Button(root,text='人气榜',command=lambda : 排行(a=1)) 202 but5=Button(root,text='口碑榜',command=lambda : 排行(a=2)) 203 but6=Button(root,text='收藏榜',command=lambda : 排行(a=3)) 204 but7=Button(root,text='打赏榜',command=lambda : 排行(a=4)) 205 but8=Button(root,text='完结榜',command=lambda : 排行(a=5)) 206 but9=Button(root,text='开始下载2',font=('KaiTi',13,'bold'),bg='red',fg='green',width=10,command=bbb) 207 but1=Button(root,text='搜 索',command=搜索) 208 but2.grid() 209 but1.grid() 210 but3.grid() 211 but4.grid() 212 but5.grid() 213 but6.grid() 214 but7.grid() 215 but8.grid() 216 but9.grid() 217 E3 = Entry(root, bd =5) 218 E3.grid(row=4,column=1,sticky=W) 219 cv2 = tkinter.StringVar() 220 com2 = ttk.Combobox(root, textvariable=cv2,width=35) 221 com2.grid(row=7, column=1) 222 text.set('欢迎使用by斌') 223 lable4 = Label(root,textvariable=text) 224 lable4.grid(row=9,column=1) 225 root.mainloop()
标签:get,url,data,mh,replace,漫画,root,下载 来源: https://www.cnblogs.com/wangbin2020/p/13871377.html