@@ -56,19 +56,29 @@ def download_images(url_list):
56
56
57
57
if html is not None :
58
58
bs = BeautifulSoup (html , "html.parser" )
59
- image = bs .find ("img" , {"class" : "ui_wikidb_main_img" })
60
- character = bs .find ("a" , {"class" : "ui_page_match" })
61
- name = bs .find ("h2" , {"id" : "js_wikidb_main_name" })
62
59
60
+ # image link
61
+ image = bs .find ("img" , {"class" : "ui_wikidb_main_img" })
63
62
image_url = image ['src' ]
64
- character_name = character ['title' ]
65
- filename = f"{ name .text } .jpg"
66
- character_dir = os .path .join (OUTPUT_FOLDER , character_name )
67
63
64
+ # character
65
+ character = bs .select_one ('.ui_wikidb_top_pc > p:nth-child(2) > span:nth-child(1)' )
66
+ next_elem = character .findNext ()
67
+ if next_elem .name == "a" :
68
+ character_name = next_elem ['title' ].strip ()
69
+ else :
70
+ character_name = next_elem .previous_sibling .text .strip ()
71
+
72
+ # card name
73
+ card_name = bs .find ("h2" , {"id" : "js_wikidb_main_name" })
74
+
75
+ # output path
76
+ filename = f"{ card_name .text .strip ()} .jpg"
77
+ character_dir = os .path .join (OUTPUT_FOLDER , character_name )
68
78
if not os .path .exists (character_dir ):
69
79
os .makedirs (character_dir , exist_ok = True )
70
-
71
80
output_file = os .path .join (character_dir , filename )
81
+
72
82
urllib .request .urlretrieve (image_url , filename = output_file )
73
83
74
84
0 commit comments