首先找到三个接口
第一个是英雄武器的接口
# 武器URL地址
weapon_url = "http://gamehelper.gm825.com/wzry/equip/list"
第二个是英雄列表接口
# 英雄列表URL地址
heros_url = "http://gamehelper.gm825.com/wzry/hero/list"
第三个是英雄出装的接口
第三个接口有点特殊,需要前面的英雄id,也就是hero_id
# 英雄出装URL hero_url = "http://gamehelper.gm825.com/wzry/hero/detail?hero_id={}".format(hero_id)
下面就是愉快的代码之旅了~
>首先导入两个库 from urllib.request import urlretrieve import requests
>先热热身,通过urllib下载王者荣耀得英雄图片,下面是部分代码:
运行后下载图片:
>接下来是获取英雄的名字和ID,代码如下:
运行效果如图所示:
这个时候运行会有一些问题,seek_weapon函数还没有定义,接下来定义seek_weapon,代码如下:
seek_weapon函数在调用的时候,需要weapon_info,也就是所有武器的字典,这个时候就需要在定义一个函数来获取武器的字典
另附headers
headers = { 'Accept-Charset': 'UTF-8', 'Accept-Encoding': 'gzip,deflate', 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 6.0.1; MI 5 MIUI/V8.1.6.0.MAACNDI)', 'X-Requested-With': 'XMLHttpRequest', 'Content-type': 'application/x-www-form-urlencoded', 'Connection': 'Keep-Alive', 'Host': 'gamehelper.gm825.com' }
最终的运行效果下图:
需要相关文件代码,关注+转发然后加群:791052257获取