赞
踩
本次爬取为App爬虫入门案例,不进行过多复杂操作,旨在快速入门!!!
爬取目标: 王者荣耀全英雄的名称、类型、热度、胜率、登场率、Ban率
部分截图如下:
打开App
进入首页(需要登陆)
选择英雄,点击全部
请求头
请求头信息详解
请求体
对JSON数据进行在线解析
所需全部数据在data下的list中
英雄的名称、类型、热度、胜率、登场率、Ban率
可见数据是我们想要的
import requests import json import xlsxwriter as xw import os headers = { "Host": "ssl.kohsocialapp.qq.com:10001", "Connection": "keep-alive", "Content-Length": "1068", "Origin": "https://camp.qq.com", "User-Agent": "Mozilla/5.0 (Linux; Android 5.1.1; TAS-AN00 Build/TAS-AN00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36;GameHelper; smobagamehelper; Brand: HUAWEI TAS-AN00$", "X-Client-Proto": "https", "Accept": "application/json, text/plain, */*", "noencrypt": "1", "Content-Type": "application/x-www-form-urlencoded", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7", "X-Requested-With": "com.tencent.gamehelper.smoba" } url = "https://ssl.kohsocialapp.qq.com:10001/hero/getdetailranklistbyid" data = { "userId": "1835412780", "openid": "oFhrws9p-nFsxqRsGu94Lwhp0xck", "source": "smoba_zhushou", "msdkToken": "" #自己查看填写 } response = requests.post(url=url, headers=headers, data=data) details = json.loads(response.text) lists = details['data']['list'] work = xw.Workbook("./res.xlsx") # 不存在就创建,存在就报错 # 新建工作表 sheet = work.add_worksheet("one") sheet.write(0, 0, "名称") sheet.write(0, 1, "类型") sheet.write(0, 2, "热度") sheet.write(0, 3, "胜率") sheet.write(0, 4, "登场率") sheet.write(0, 5, "Ban率") cur = 0 for i in lists: name = i['heroInfo'][0]['heroName'] type = i['heroInfo'][0]['heroCareer'] winRate = format(float(i['winRate']) * 100, '.2f') + "%" showRate = format(float(i['showRate']) * 100, '.2f') + "%" banRate = format(float(i['banRate']) * 100, '.2f') + "%" tRank = i['tRank'] sheet.write(cur, 0, name) sheet.write(cur, 1, type) sheet.write(cur, 2, tRank) sheet.write(cur, 3, winRate) sheet.write(cur, 4, showRate) sheet.write(cur, 5, banRate) cur += 1 # 关闭 work.close()
我是 Code皮皮虾,一个热爱分享知识的 皮皮虾爱好者,未来的日子里会不断更新出对大家有益的博文,期待大家的关注!!!
创作不易,如果这篇博文对各位有帮助,希望各位小伙伴可以一键三连哦!,感谢支持,我们下次再见~~~
分享大纲
更多精彩内容分享,请点击 Hello World (●’◡’●)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。