Merge branch 'main' of https://git.wmi.amu.edu.pl/s444498/wko_anime-face-similarity
This commit is contained in:
commit
c94a3c916d
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
images
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
@ -1,7 +1,7 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from lxml import etree
|
||||
import re
|
||||
import os
|
||||
|
||||
ROOT_URL = "https://myanimelist.net/character.php"
|
||||
|
||||
@ -12,16 +12,24 @@ def get_page_xpath_result(url, xpath_str):
|
||||
dom = etree.HTML(str(soup))
|
||||
return dom.xpath(xpath_str)
|
||||
|
||||
# 1. face image
|
||||
# 2. character name
|
||||
# 3. link
|
||||
|
||||
character_links = get_page_xpath_result(ROOT_URL, '//div[@class="information di-ib mt24"]/a/@href')
|
||||
character_names = get_page_xpath_result(ROOT_URL, '//div[@class="information di-ib mt24"]/a')
|
||||
character_names = [link.text for link in character_names]
|
||||
|
||||
print("character_links")
|
||||
print(character_links)
|
||||
character_img_urls = [get_page_xpath_result(link, '//td/div/a/img/@data-src')[0]
|
||||
for link in character_links]
|
||||
|
||||
path = './images'
|
||||
isExist = os.path.exists(path)
|
||||
if not isExist:
|
||||
os.makedirs(path)
|
||||
print("The images directory is created!")
|
||||
|
||||
for name, url in zip(character_names, character_img_urls):
|
||||
img_data = requests.get(url).content
|
||||
with open(f'images/{name}.jpg', 'wb') as handler:
|
||||
handler.write(img_data)
|
||||
handler.close()
|
||||
print(f'{name}.jpg downloaded')
|
||||
|
||||
|
||||
print("character_names")
|
||||
print(character_names)
|
Loading…
Reference in New Issue
Block a user