"""
Author:Ren Yulian
Create Time: 2023/3/27 17:18
Happy every day!
"""
import requests
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
'cookie': 'eas_sid=W1d6m7V9P9S0J7m4O2Q095p4m4; isHostDate=19443; PTTuserFirstTime=1679875200000; pgv_info=ssid=s1270348260; pgv_pvid=228582244; ts_uid=142632659; weekloop=0-0-0-13; tokenParams=%3Fid%3D1; ts_last=lol.qq.com/data/info-defail.shtml; lolqqcomrouteLine=data_data_data_data_data'
}
response = requests.get('https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js', headers=headers)
for heroes in response.json()['hero']:
hero_id = heroes['heroId']
response1 = requests.get(f'https://game.gtimg.cn/images/lol/act/img/js/hero/{hero_id}.js', headers=headers)
for skins in response1.json()['skins']:
name = skins['name']
skinId = skins['skinId']
try:
response2 = requests.get(skins['mainImg'], headers=headers)
except requests.exceptions.MissingSchema:
response2 = requests.get(skins['chromaImg'], headers=headers)
except FileNotFoundError:
pass
result = response2.content
with open(f'files/heroes/{skinId} {name}.jpg', 'wb') as f:
f.write(result)
def get_all_hero_id():
response = requests.get('https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js')
result = response.json()
return [x['heroId'] for x in result['hero']]
def download(hero_name, skin_name, skin_url):
if os.path.exists(f'files/{hero_name}'):
os.mkdir(f'files/{hero_name}')
response = requests.get(skin_url)
with open(f'files/{hero_name}/{skin_name}.jpg', 'wb') as f:
f.write(response.content)
def get_hero_skin_url(hero_id):
url = f'https://game.gtimg.cn/images/lol/act/img/js/hero/{hero_id}.js'
response = requests.get(url)
for x in response.json()['skins']:
hero_name = x['heroTitle']
skin_name = x['name'].replace('/', ' ')
skin_url = x['mainImg'] if x['mainImg'] else x['chromaImg']
download(hero_name, skin_name, skin_url)
if __name__ == '__main__':
for x in get_all_hero_id():
get_hero_skin_url(x)