import requests
import os
import jsonpath
from urllib.request import urlretrieve
#获取ID
def get_id():
url = 'https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js'
headers = {
'user - agent': 'Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 81.0.4044.138Safari / 537.36'
}
response = requests.get(url=url, headers=headers)
r = response.json()
ids = jsonpath.jsonpath(r, '$..heroId')
print(ids)
print("英雄的个数为: " + str(len(ids)))
return ids
#获取皮肤
def get_skins(ids):
headers = {
'user - agent': 'Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 81.0.4044.138Safari / 537.36'
}
for heroId in ids:
url = 'https://game.gtimg.cn/images/lol/act/img/js/hero/{}.js'.format(heroId)
response = requests.get(url=url, headers=headers).json()
skins = response['skins']
Img = jsonpath.jsonpath(skins, '$..mainImg')
names = jsonpath.jsonpath(response, '$..name')
try:
if not os.path.exists(names[0]):
os.mkdir(names[0])
for name, Imgs in zip(names, Img):
urlretrieve(Imgs,names[0] + '/' + name + '.jpg')
except:
pass
print('<%s>' % names)
id_list = get_id()
get_skins(id_list)
人生漫漫其修远兮,网安无止境。
一同前行,加油!