-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmscraper.py
48 lines (37 loc) · 1.31 KB
/
mscraper.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
import traceback
import requests
import os
import bs4
manga = 'sousei-no-onmyouji'
url = 'http://www.mangareader.net/sousei-no-onmyouji'
os.makedirs(manga, exist_ok=True)
chapter = 1
chapter_exist = True
while chapter_exist:
page = 1
page_exist = True
os.makedirs("{}/{}".format(manga, chapter), exist_ok=True)
print("Downloading chapter: {}".format(chapter))
while page_exist:
try:
res = requests.get('{}/{}/{}'.format(url, chapter, page))
res.raise_for_status()
if res.status_code != 404:
soup = bs4.BeautifulSoup(res.text)
img = soup.select('#img')
img_url = img[0].get('src')
print(' Downloading image: {}'.format(img_url))
res = requests.get(img_url)
res.raise_for_status()
with open(os.path.join(manga + "/{}".format(chapter),
os.path.basename(img_url)), 'wb') as image_file:
for chunk in res.iter_content(1000000):
image_file.write(chunk)
page += 1
else:
page_exist = False
except:
page_exist = False
print(traceback.print_exc())
chapter += 1
print("{} downloaded".format(manga))