-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaofly.py
60 lines (45 loc) · 1.83 KB
/
maofly.py
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
from lxml import etree
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED
import os
import re
import time
import requests
from lzstring import LZString
pool = ThreadPoolExecutor(max_workers=32)
def downloadImage(page_filename, page_url):
res = requests.get(page_url, headers={
'Referer': 'https://www.maofly.com/'})
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'https://www.maofly.com/manga/{id}.html')
myhtml = etree.HTML(response.content.decode())
chapter_url_list = myhtml.xpath("//a[@class='fixed-a-es']/@href")
chapter_name_list = myhtml.xpath("//a[@class='fixed-a-es']/@title")
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}')
print(chapter_name)
response = requests.get(chapter_url)
img_data = re.findall(r'img_data = "(.*?)"', response.text)[0]
page_url_list = LZString.decompressFromBase64(img_data).split(',')
page = 1
for page_url in page_url_list:
page_filename = f'.\\{page}.jpg'
downloadImage(
page_filename, f'http://mao.mhtupian.com/uploads/{page_url}')
time.sleep(0.1)
# task_list.append(pool.submit(
# downloadImage, page_filename, f'https://mao.mhtupian.com/uploads/{page_url}'))
page += 1
os.chdir('..')
wait(task_list, return_when=ALL_COMPLETED)
auto(114514, 'example') # 第一个参数为漫画id,第二个为目录名称