前言
本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理。
PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取
基本环境配置
- python 3.6
- pycharm
- requests
相关模块pip安装即可
目标网页
经过一些系列的网页分析,可以发现它的图片地址
https://yys.res.netease.com/pc/zt/20161108171335/data/shishen_big_beforeAwake/201.png
https://yys.res.netease.com/pc/zt/20161108171335/data/shishen_big_afterAwake/201.png
https://yys.res.netease.com/pc/zt/20161108171335/data/shishen_skin/201-1.png
多看几张式神的图片后可以发现,每个图片所改变的是式神的 ID 值
可以通过开发者工具抓包,找到数据接口
请求数据
- 获得json数据
import requests
url = 'https://yys.res.netease.com/pc/zt/20161108171335/js/app/all_shishen.json'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'
}
response = requests.get(url=url, headers=headers)
html_data = response.json()
解析数据
- 获取
id
值 以及式神名字
- 构建图片地址
for i in html_data:
num_id = i['id']
name = i['name']
beforeAwake = 'https://yys.res.netease.com/pc/zt/20161108171335/data/shishen_big_beforeAwake/{}.png'.format(num_id)
afterAwake = 'https://yys.res.netease.com/pc/zt/20161108171335/data/shishen_big_afterAwake/{}.png'.format(num_id)
skin = 'https://yys.res.netease.com/pc/zt/20161108171335/data/shishen_skin/{}-1.png'.format(num_id)
beforeAwake_response = requests.get(url=beforeAwake, headers=headers)
beforeAwake_name = name + '初始' + '.png'
afterAwake_response = requests.get(url=beforeAwake, headers=headers)
afterAwake_name = name + '觉醒' + '.png'
skin_response = requests.get(url=beforeAwake, headers=headers)
skin_name = name + '皮肤' + '.png'
保存数据
path = 'D:\\python\\demo\\阴阳师\\img\\'
def download(name, response):
with open(path + name, mode='wb') as f:
f.write(response.content)
完整代码
import requests
import pprint
url = 'https://yys.res.netease.com/pc/zt/20161108171335/js/app/all_shishen.json'
path = 'D:\\python\\demo\\阴阳师\\img\\'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'
}
def download(name, response):
with open(path + name, mode='wb') as f:
f.write(response.content)
response = requests.get(url=url, headers=headers)
html_data = response.json()
for i in html_data:
num_id = i['id']
name = i['name']
beforeAwake = 'https://yys.res.netease.com/pc/zt/20161108171335/data/shishen_big_beforeAwake/{}.png'.format(num_id)
afterAwake = 'https://yys.res.netease.com/pc/zt/20161108171335/data/shishen_big_afterAwake/{}.png'.format(num_id)
skin = 'https://yys.res.netease.com/pc/zt/20161108171335/data/shishen_skin/{}-1.png'.format(num_id)
beforeAwake_response = requests.get(url=beforeAwake, headers=headers)
beforeAwake_name = name + '初始' + '.png'
download(beforeAwake_name, beforeAwake_response)
afterAwake_response = requests.get(url=beforeAwake, headers=headers)
afterAwake_name = name + '觉醒' + '.png'
download(afterAwake_name, afterAwake_response)
skin_response = requests.get(url=beforeAwake, headers=headers)
skin_name = name + '皮肤' + '.png'
download(skin_name, skin_response)
print('正在下载{}图鉴'.format(name))
实现效果