💻 源代码
import requests
from lxml import etree
import os
import re
url = 'http://ddragon.leagueoflegends.com/cdn/6.24.1/data/en_US/champion.json'
def get_hero_name(url):
"""获取所有英雄名称"""
head = {
'User-Agent': 'Mozilla/5.0 Chrome/60.0.3112.113'
}
html = requests.get(url, headers=head)
html_json = html.json()
hero_names = list(html_json['data'].keys())
return hero_names
def download_hero_skins():
"""下载所有英雄皮肤"""
heroes = get_hero_name(url)
for fn in heroes:
path = f'LOLPic/{fn}'
if not os.path.exists(path):
os.mkdir(path)
for v in range(20):
skin_url = f'http://ddragon.leagueoflegends.com/cdn/img/champion/splash/{fn}_{v}.jpg'
im = requests.get(skin_url)
if im.status_code == 200:
with open(f'{path}/{fn}_{v}.jpg', 'wb') as f:
f.write(im.content)
print(f"下载 {fn} 皮肤 {v}")
if __name__ == '__main__':
download_hero_skins()