-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdm5.py
More file actions
79 lines (57 loc) · 2.36 KB
/
dm5.py
File metadata and controls
79 lines (57 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import time
import os
import re
import execjs
import requests
from lxml import etree
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED
pool = ThreadPoolExecutor(max_workers=4)
DOMAIN = "https://www.dm5.com"
def downloadImage(headers, page_filename, page_url):
res = requests.get(page_url, headers=headers)
file = open(page_filename, 'wb')
file.write(res.content)
def auto(id, cname):
if not os.path.exists(cname):
os.makedirs(cname)
os.chdir(f'.\\{cname}')
response = requests.get(f'{DOMAIN}/{id}/')
html = etree.HTML(response.text)
chapter_name_list=[]
chapter_url_list = []
chapter_name_list.extend(html.xpath(
'//div[@id="chapterlistload"]/ul/li/a/text()[1]'))
chapter_url_list.extend(html.xpath(
'//div[@id="chapterlistload"]/ul/li/a/@href'))
chapter_name_list.extend(html.xpath(
'//ul[@class="chapteritem"]/li/a/text()[1]'))
chapter_url_list.extend(html.xpath(
'//ul[@class="chapteritem"]/li/a/@href'))
task_list = []
for chapter_name, chapter_url in zip(chapter_name_list, chapter_url_list):
if os.path.exists(f'.\\{chapter_name}'):
continue
os.mkdir(f'.\\{chapter_name}')
os.chdir(f'.\\{chapter_name}')
headers = {'Referer': f'{DOMAIN}/{id}/'}
content = requests.get(f'{DOMAIN}{chapter_url}', headers=headers)
pattern = re.compile(
'.*?DM5_MID=(.*?);'
'.*?DM5_CID=(.*?);'
'.*?DM5_IMAGE_COUNT=(.*?);'
'.*?DM5_VIEWSIGN="(.*?)";'
'.*?DM5_VIEWSIGN_DT="(.*?)";', re.S)
mid, cid, image_count, sign, date = pattern.findall(content.text)[0]
for i in range(1, int(image_count)):
content = requests.get(
f'{DOMAIN}/{id}/chapterfun.ashx?cid={cid}&page={i}&key=&language=1>k=6&_cid={cid}&_mid={mid}&_dt={date}&_sign={sign}', headers=headers)
js = "function run(){{return {0:s}}}".format(content.text[5:-2])
ctx = execjs.compile(js).call('run')
ctx = execjs.compile(ctx).call('dm5imagefun')
page_filename = f'.\\{i}.jpg'
task_list.append(pool.submit(
downloadImage,headers, page_filename, ctx[0]))
time.sleep(0.1)
wait(task_list, return_when=ALL_COMPLETED)
os.chdir('..')
auto('manhua-example', 'example')