您当前的位置: 首页 >  Python

嗨学编程

暂无认证

  • 0浏览

    0关注

    1405博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

python爬取英雄联盟官网所有英雄皮肤数据

嗨学编程 发布时间:2020-09-15 00:37:27 ,浏览量:0

前言

本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理。

PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取

python免费学习资料以及群交流解答点击即可加入

基本环境配置
  • python 3.6
  • pycharm
  • requests
网页分析

在这里插入图片描述 在这里插入图片描述

import requests
import pprint
url = 'https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js'

headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Referer': 'https://lol.qq.com/data/info-heros.shtml',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36',
}

response = requests.get(url=url, headers=headers)
html_data = response.json()
pprint.pprint(html_data)

在这里插入图片描述

解析网页数据
heroes = html_data['hero']
lis = []
for hero in heroes:
    hero_id = hero['heroId']
    lis.append(hero['heroId'])

for li in lis:
    hero_url = 'https://game.gtimg.cn/images/lol/act/img/js/hero/{}.js'.format(li)
    response = requests.get(url=hero_url, headers=headers)
    hero_data = response.json()
    skins = hero_data['skins']
    for skin in skins:
        time.sleep(1)
        img_url = skin['mainImg']
        name = skin['name']
        xuancai_url = skin['chromaImg']
保存数据
response = requests.get(url=img_url, headers=headers)
with open('G:\\python\\demo\\案例\\英雄联盟\\img\\' + name + '.jpg', mode='wb') as f:
    f.write(response.content)
    print('{}下载完成'.format(name))
实现效果

在这里插入图片描述 在这里插入图片描述

关注
打赏
1663681728
查看更多评论
立即登录/注册

微信扫码登录

0.0502s