打野最快的英雄lol(python爬取英雄联盟官网所有英雄皮肤数据)
本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理。
PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取
python免费学习资料以及群交流解答点击即可加入
基本环境配置- python 3.6
- pycharm
- requests
import requests
import pprint
url = 'https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js'
headers = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Referer': 'https://lol.qq.com/data/info-heros.shtml',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36',
}
response = requests.get(url=url, headers=headers)
html_data = response.json()
pprint.pprint(html_data)
解析网页数据
heroes = html_data['hero']
lis = []
for hero in heroes:
hero_id = hero['heroId']
lis.append(hero['heroId'])
for li in lis:
hero_url = 'https://game.gtimg.cn/images/lol/act/img/js/hero/{}.js'.format(li)
response = requests.get(url=hero_url, headers=headers)
hero_data = response.json()
skins = hero_data['skins']
for skin in skins:
time.sleep(1)
img_url = skin['mainImg']
name = skin['name']
xuancai_url = skin['chromaImg']
response = requests.get(url=img_url, headers=headers)
with open('G:\\python\\demo\\案例\\英雄联盟\\img\\' name '.jpg', mode='wb') as f:
f.write(response.content)
print('{}下载完成'.format(name))
,
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com