文章目錄
- 前言
- 資料分析
- 完整代碼
- 最后
前言
本次爬取為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皮皮蝦,一個熱愛分享知識的 皮皮蝦愛好者,未來的日子里會不斷更新出對大家有益的博文,期待大家的關注!!!
創作不易,如果這篇博文對各位有幫助,希望各位小伙伴可以一鍵三連哦!,感謝支持,我們下次再見~~~
分享大綱
大廠面試題專欄
Java從入門到入墳學習路線目錄索引
開源爬蟲實體教程目錄索引
更多精彩內容分享,請點擊 Hello World (●’?’●)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/290487.html
標籤:其他
上一篇:走進爬蟲的世界
