python 阴阳师 识别图像_Python采集阴阳师式神全图鉴图片

该博客介绍了如何使用Python爬虫从阴阳师网站抓取式神的初始、觉醒和皮肤图片。通过分析网页数据接口,获取JSON数据,然后解析ID和式神名字,构造图片URL并下载到本地。

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

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

66517.htmlwAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

多看几张式神的图片后可以发现,每个图片所改变的是式神的 ID 值

可以通过开发者工具抓包,找到数据接口

66517.htmlwAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

请求数据

获得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()

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

解析数据

获取 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'

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

保存数据

path = 'D:pythondemo阴阳师img'

def download(name, response):

with open(path + name, mode='wb') as f:

f.write(response.content)

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

完整代码

import requests

import pprint

url = 'https://yys.res.netease.com/pc/zt/20161108171335/js/app/all_shishen.json'

path = 'D:pythondemo阴阳师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))

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

实现效果

66517.htmlwAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

66517.htmlwAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

66517.htmlwAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

66517.htmlwAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

66517.htmlwAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值