admin管理员组文章数量:1619183
滴滴滴,这几天忙着增强自己的实力,发现了一个非常适合新手的案例
案例就是爬取英雄联盟的所有英雄名称和技能,废话不多说,我们来分析分析
要练手的链接
进入此网站我们会发现,网页上的响应数据里面并没有我们想要的数据,由此我们可以猜测,该响应的数据格式为json数据
猜测是json数据格式的相应内容,我们可以进入xhr中寻找我们想要的数据包
我们会发现,里面有一个叫hero数据包,里面有我们想要的数据
然后我们来分析获取单个英雄的技能数据,同样的这个数据包也是json格式的
我们分析会发现我们需要上个json数据中的heroId并传给第二个json数据的网址中,就能得到相应的英雄技能,分析完毕代码如下:
"""
网址:https://game.gtimg/images/lol/act/img/js/heroList/hero_list.js
目标:获取所有英雄的名称和技能名
数据结构:json
数据请求方式:ajax
"""
import requests
url = 'https://game.gtimg/images/lol/act/img/js/heroList/hero_list.js'
headers_ = {
'Referer': 'https://lol.qq/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36',
}
response = requests.get(url=url,headers=headers_).json()
# print(response)
json_data = response['hero']
for j in json_data:
heroId= j['heroId']
hero_name = j['name']
# print(hero_name)
detail_url = f'https://game.gtimg/images/lol/act/img/js/hero/{heroId}.js'
skill_response = requests.get(url=detail_url,headers=headers_).json()
# print(skill_response['spells'])
skills_list = skill_response['spells']
ls_=[]
for skill in skills_list:
# print(skill['name'])
skills = skill['name']
ls_.append(skills)
print("英雄名:",hero_name,"技能:",ls_)
不懂的可以私信博主哦,一起努力一起进步💪,(●ˇ∀ˇ●)
版权声明:本文标题:python爬虫入门案例(爬取lol所有英雄名称及技能) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1728793284a1173924.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论