-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (58 loc) · 2.84 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from bs4 import BeautifulSoup
import requests
import os
if not os.path.exists("output"):
os.mkdir("output")
firstUrl: str = ""
downloadCount: int = 1
pageCount: int = 1
while True:
response = requests.get(f"https://worldflipper.jp/character/?p={pageCount}")
if response.status_code == 404:
break
soup = BeautifulSoup(response.text, "lxml")
results = soup.find_all("ul", {"class": "char-list"})
for result in results:
for character in result.find_all("li"):
character_name = character.find("a").text.replace("\n", "")
character_url = character.find("a")["href"]
character_img = character.find("img")["src"]
if firstUrl == "":
firstUrl = character_url
else:
if character_url == firstUrl:
break
print(f">>> {character_name} -- {downloadCount} in page({pageCount})")
response = requests.get(f"https://worldflipper.jp{character_url}")
soup = BeautifulSoup(response.text, "lxml")
downloadResults = soup.find_all("a", {"rel": "noopener noreferrer"})
for downloadLink in downloadResults:
# href = downloadLink["href"]
href = downloadLink.get("href")
if "dot_front" in href:
if not os.path.exists(f"output/{downloadCount}_{character_name}_dot_front.png"):
print(f"Downloading image file: {href}")
imageRequest = requests.get(href)
with open(f"output/{downloadCount}_{character_name}_dot_front.png", "wb") as file:
file.write(imageRequest.content)
else:
print(f"Skip: {href}")
if "illust_0" in href:
if not os.path.exists(f"output/{downloadCount}_{character_name}_illust_0.png"):
print(f"Downloading image file: {href}")
imageRequest = requests.get(href)
with open(f"output/{downloadCount}_{character_name}_illust_0.png", "wb") as file:
file.write(imageRequest.content)
else:
print(f"Skip: {href}")
if "illust_1" in href:
if not os.path.exists(f"output/{downloadCount}_{character_name}_illust_1.png"):
print(f"Downloading image file: {href}")
imageRequest = requests.get(href)
with open(f"output/{downloadCount}_{character_name}_illust_1.png", "wb") as file:
file.write(imageRequest.content)
else:
print(f"Skip: {href}")
downloadCount += 1
pageCount += 1
exit(0)