import requests
import os
import jsonpath
from urllib.request import urlretrieve
#皮肤保存在D盘先在D盘新建一个lolskins空文件夹
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'}
def get_ids():
url='https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js'
r=requests.get(url,headers=headers).json()
ids=jsonpath.jsonpath(r,'$..heroId')
print('共有英雄',len(ids))
return ids
def get_skins(ids):
for id in ids:
hero_url='https://game.gtimg.cn/images/lol/act/img/js/hero/{}.js'.format(id)
hero_data=requests.get(hero_url,headers=headers).json()
skins=hero_data['skins']
names=jsonpath.jsonpath(skins,'$..name') #每个英雄皮肤的所有名字
images=jsonpath.jsonpath(skins,'$..mainImg') #每个英雄的所有皮肤
try:
if not os.path.exists(names[0]):
os.mkdir('D:/lolskins/'+names[0])
for name,image in zip(names,images):
urlretrieve(image,'D:/lolskins/'+names[0]+'/'+name+'.jpg')
except:
pass
print(f'{names[0]}下载成功')
if __name__ == '__main__':
ids=get_ids()
get_skins(ids)
|