python爬取LOL皮肤图片

94 阅读1分钟
import requests
import re
url = 'https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js'

response = requests.get(url)

json_data = response.json()

skins=[]

for item in json_data['hero']:
    skinsUrl = F'https://game.gtimg.cn/images/lol/act/img/js/hero/{item["heroId"]}.js'
    skinsRes = requests.get(skinsUrl)
    data = skinsRes.json()
    skins.append(data['skins'])

for skin in skins:
    for i in skin:
        # mainImg:"https://game.gtimg.cn/images/lol/act/img/skin/big_0b95894e-0df2-470e-b282-6c5f5cf41955.jpg"
        # name:"黑暗之女"
        name = re.sub(r'/',' ',i['name'])
        addres = f'e:/dama/python/pythonProject/LOLimg/{name}.jpg'
        if i['mainImg']:
            with open(addres, "wb") as fp:
                try:
                    req = requests.get(i['mainImg'])
                    fp.write(req.content)
                    print(F"图片下载成功,图片地址:{i['mainImg']},图片名字:{i['name']}")
                except:
                    print('图片下载失败')

微信截图_20240904113541.png