get_all_list.py
def get_all_list():
import requests
res = requests.get('https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js')
result = res.json()
with open('files/all.txt', 'w', encoding='gbk') as f:
f.write(f'{result}')
print('-------获取英雄列表信息已完成(all.txt)-------')
get_num.py
def get_name_heroId():
heroId = []
name = []
with open('files/all.txt', 'r', encoding='gbk') as f:
all_dic = eval(f.read())
for x in all_dic['hero']:
heroId.append(x['heroId'])
name.append(x['name'])
with open('files/heroId.txt', 'w', encoding='utf-8') as f:
f.write(str(heroId))
print('-------获取英雄ID已完成(heroId.txt)-------')
with open('files/name.txt', 'w', encoding='utf-8') as f:
f.write(str(name))
print('-------获取英雄名字已完成(name.txt)-------')
主体代码
import requests
import os
import get_num
import get_all_list
get_all_list.get_all_list()
get_num.get_name_heroId()
with open('files/name.txt', 'r', encoding='utf-8') as f:
names = eval(f.read())
print('-------已导出英雄名字-------')
with open('files/heroId.txt', 'r', encoding='utf-8') as f:
heroid = eval(f.read())
print('-------已导出英雄id-------')
for x in heroid:
try:
name_ = names[heroid.index(x)]
pic_all = requests.get(f'https://game.gtimg.cn/images/lol/act/img/js/hero/{x}.js', headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'} )
skins = pic_all.json()['skins']
path = f'files/英雄皮肤/{name_}'
try:
os.mkdir(path)
except FileExistsError:
pass
for x in skins:
if x['mainImg'] == '':
continue
else:
ski = requests.get(x['mainImg']).content
with open(f"files/英雄皮肤/{name_}/{x['name']}.jpg", 'wb') as f:
f.write(ski)
except FileNotFoundError:
continue
print('全部完成')