Python—爬取王者荣耀官网全英雄图片,包括图片命名英雄名字

一、引言

在王者荣耀这个热门游戏中,英雄形象各具特色,深受玩家喜爱。为了方便对这些英雄图片进行整理和研究,本文将详细介绍如何爬取王者荣耀官网的全英雄图片,并按照英雄名字进行命名。

二、准备工作

  1. 熟悉 Python 编程语言,特别是相关的网络请求和文件操作库。
  2. 安装所需的库,如 requests 用于发送网络请求, BeautifulSoup 用于解析 HTML 等。

三、分析王者荣耀官网结构

通过浏览器开发者工具,观察王者荣耀官网中英雄图片的加载方式和存储路径。

四、编写爬取代码

注意:需在该py文件同级目录下创建一个名为head的文件用来存储图片

from urllib import request
import json


response = request.urlopen("https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js?ts=2867062")

response = response.read().decode("utf8")
response = json.loads(response)['hero']
print(response)
for dates in response:
    head_url = f"https://game.gtimg.cn/images/lol/act/img/skinloading/{dates['instance_id']}.jpg"
    print(head_url)
    cname = dates['title']
    # print(cname, head_url)
    head_response = request.urlopen(head_url)
    head_response = head_response.read()
    file = open(f"./head/{cname}.jpg", "wb")
    file.write(head_response)
    file.close()
    print(f"保存 {cname} 成功")

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值