import requests
from fake_useragent import UserAgent
from urllib.request import urlretrieve
from time import sleep
def get_hero_img(hero_id):
url = f'https://game.gtimg.cn/images/lol/act/img/js/hero/{hero_id}.js'
# 构建请求头
headers = {'User-Agent':UserAgent().chrome}
# 发送请求
resp = requests.get(url,headers=headers)
# 获取响应内容
for sk in resp.json().get('skins'):
name = sk.get('name').replace(" ","_")
img_url = sk.get('mainImg')
if sk.get('mainImg'):
print(f"皮肤名:{name}===皮肤下载地址:{img_url}")
urlretrieve(img_url,filename=f'./imgs/lol/{name}.jpg')
sleep(1)
def get_hero_list():
url = 'https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js'
# 构建请求头
headers = {'User-Agent':UserAgent().chrome}
# 发送请求
resp = requests.get(url,headers=headers)
# 获取响应内容
for h in resp.json().get('hero'):
hero_id = h.get('heroId')
hero_name = h.get('name')
# 将数据一一返回
yield (hero_id,hero_name)
if __name__ == '__main__':
# get_hero_img()
for hero_id,hero_name in get_hero_list():
print(f"================正在下载:英雄{hero_name}===================")
get_hero_img(hero_id)
print(f"================下载完成:英雄{hero_name}===================")
标签:hero,name,img,get,url,皮肤,LOL,id From: https://www.cnblogs.com/jiangjiayun/p/17538814.html