GitHub+Hexo快速搭建个人博客

英雄联盟皮肤爬虫

import os

import requests

# 1.获取数据
response = requests.get('https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js')
ls = []

for x in response.json()['hero']:
    ls.append(x['heroId'])

for i in ls:
    addr = f'https://game.gtimg.cn/images/lol/act/img/js/hero/{i}.js'
    response1 = requests.get(addr)

    for x in response1.json()['skins']:
        hero_name = x['heroTitle']
        skin_name = x['name'].replace('/', '')
        skin_url = x['mainImg'] if x['mainImg'] else x['chromaImg']
        # 创建英雄对应的文件夹
        if not 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)
        print(f'----------{skin_name}下载完成---------------')

猜你喜欢

转载自blog.csdn.net/cnroot001/article/details/118190515