Python学习笔记第25天

谏言:穷则独善其身,达则兼济天下

import requests
# 请求地址
def get_lol_list():
    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, like Gecko) Chrome/81.0.4044.122 Safari/537.36' 
    }
    # 发送请求
    img_lol=requests.get(url,headers=headers).json()
    hero_list=img_lol['hero']
    for lol in hero_list:
        id=lol['heroId']
        new_url='https://game.gtimg.cn/images/lol/act/img/js/hero/{}.js'.format(id)
        img_data=requests.get(new_url,headers=headers).json()
        skins_list=img_data['skins']
        for j in skins_list:
            # print(j)
            name=j['name']
            mainimg=j['mainImg']
            # print(name,mainimg)
            if mainimg:
                res=requests.get(mainimg).content
#             try:
                with open('皮肤图片/'+name+'.jpg','wb') as f:
                    f.write(res)
                    print("正在下载"+name)
#             except 
                

get_lol_list()

 

猜你喜欢

转载自www.cnblogs.com/python-study-notebook/p/12824634.html