栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python使用json接口爬取网页数据

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python使用json接口爬取网页数据

Python使用json接口爬取网页数据

示例:英雄联盟皮肤下载

"""
long long away
Date:2022/5/17 16:37
"""
import requests,json,os
from tqdm import tqdm

response = requests.get('https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js')
result = response.json()

name_list = []
for i in result['hero']:
    name_list.append(i['title'])
# print(name_list)
# print(len(name_list))
for i in tqdm(range(1,160)):

    os.mkdir(f'./files/英雄皮肤信息/{name_list[i-1]}')
    resp1 = requests.get(f'https://game.gtimg.cn/images/lol/act/img/js/hero/{i}.js')
    resp = resp1.json()

    print(i)
    for j in resp['skins']:
        name = j['name']
        if j['mainImg'] != "":
            URL = j['mainImg']
            resp2 = requests.get(url=URL)
            with open(rf'./files/英雄皮肤信息/{name_list[i - 1]}/{name}.jpg', 'wb') as f3:
                f3.write(resp2.content)
        # 炫彩皮肤
        # else:
        #     URL = j['chromaImg']
        #     resp2 = requests.get(url=URL)
        #     with open(rf'./files/英雄皮肤信息/{name_list[i - 1]}/{name}.png', 'wb') as f3:
        #         f3.write(resp2.content)




转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/892806.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号