教你如何用python爬取王者榮耀月收入流水線
前言
王者榮耀是最近幾年包括現(xiàn)在一直都是最熱銷的手游,收益主要來源是游戲里面人物皮膚。今天就來爬取展示王者榮耀近一年收入流水線動(dòng)圖,看看王者榮耀有多賺錢(哈哈哈哈)
主要可視化內(nèi)容:
一.App收入排行流水線
1.1.獲取數(shù)據(jù)
數(shù)據(jù)來源于:七麥數(shù)據(jù),里面數(shù)據(jù)都是通過異步加載,因此只需要找到異步鏈接,修改參數(shù)就可以直接獲取到數(shù)據(jù)。
備注:需要cookie才可以獲取數(shù)據(jù)。
請(qǐng)求鏈接
https://api.qimai.cn/pred/appMonthPred?analysis=eEcbRhNVVB9RQEB9VwpDUDRGUwVwEwEAAQcIClwODlQEAyETAQ%3D%3D
請(qǐng)求參數(shù)
data = { 'device': 'iphone', 'genre': 36, 'month': date[d], }
請(qǐng)求數(shù)據(jù)
date=['2020-01','2020-02','2020-03','2020-04','2020-05','2020-06','2020-07', '2020-08','2020-09','2020-10','2020-11','2020-12','2021-01','2021-02'] #app名稱: 收入情況 dict={} for d in range(0,len(date)): data = { 'device': 'iphone', 'genre': 36, 'month': date[d], } response = requests.post(url, headers=headers, data=data) text = json.loads(response.text)
將數(shù)據(jù)臨時(shí)保存到字典中
revenue_data = text['revenue_data'] for i in revenue_data: d_get = dict.get(i['app_name']) if d_get== None:#不存在 #創(chuàng)建 dict[i['app_name']]=[0]*len(date) tem_list = dict[i['app_name']] tem_list[d] = i['revenue'] dict[i['app_name']] = tem_list
保存到excel
outwb = openpyxl.Workbook() outws = outwb.create_sheet(index=0) outws.cell(row=1, column=1, value="日期") for i in range(0,len(date)): outws.cell(row=1, column=i+2, value=date[i]) ###寫入csv # 通過遍歷keys()來獲取所有的鍵 count =2 for k in dict.keys() : outws.cell(row=count, column=1, value=k) ###寫入值 tem_list = dict[k] for j in range(0,len(tem_list)): outws.cell(row=count, column=j+2, value=tem_list[j]) count = count+1 outwb.save("App收入排行_lyc.xlsx") # 保存
1.2流水線可視化
第一種方法是:花火hanabi
第二種方法:
####開始畫圖 plt.rcParams['font.sans-serif']=['SimHei'] #顯示中文標(biāo)簽 plt.rcParams['axes.unicode_minus']=False #解決負(fù)號(hào)“-”顯示為方塊的問題 # 獲取數(shù)據(jù) df = pd.read_csv("App收入排行_lyc.csv",index_col=0) # 生成動(dòng)態(tài)流水線 bcr.bar_chart_race(df=df, filename='App收入排行_lyc.mp4', #生成的動(dòng)態(tài)條形圖的文件位置 orientation='h', #h條形圖 v柱狀圖 sort='desc', #降序,asc-升序 n_bars=10, #設(shè)置最多能顯示的條目數(shù) fixed_order=False, # 設(shè)置固定類目 fixed_max=False, #固定數(shù)值軸,使其不發(fā)生動(dòng)態(tài)變化 True-固定 steps_per_period=24, #圖像幀數(shù):數(shù)值越小,越不流暢,越大,越流暢 period_length=20, #設(shè)置幀率,單位時(shí)間默認(rèn)為500ms 即為24幀的總時(shí)間是500ms end_period_pause=0,#固定值比如年份的停留時(shí)間 interpolate_period=False, period_label={'x': .80, 'y': .5, 'ha': 'right', 'va': 'center','size':16}, #設(shè)置日期標(biāo)簽的時(shí)間格式 colors='dark12', #設(shè)置柱狀圖顏色顏色,通過在「_colormaps.py」文件中添加顏色信息,即可自定義配置顏色 title={'label': 'App收入排行_lyc','size': 18,}, #圖表標(biāo)題 bar_size=.95, #條形圖高度 bar_textposition='inside',#條形圖標(biāo)簽文字位置 bar_texttemplate='{x:,.0f}', #條形圖標(biāo)簽文字格式 bar_label_font=16, #條形圖標(biāo)簽文字大小 tick_label_font=16, #坐標(biāo)軸標(biāo)簽文字大小 tick_template='{x:,.0f}',#坐標(biāo)軸標(biāo)簽文字格式 shared_fontdict={'family': 'Microsoft YaHei','color': 'rebeccapurple'}, #全局字體屬性 scale='linear', fig=None, writer=None, bar_kwargs={'alpha': .7},#條形圖屬性,可以設(shè)置透明度,邊框等 fig_kwargs={'figsize': (16, 10), 'dpi': 144},#figsize-設(shè)置畫布大小,默認(rèn)(6, 3.5),dpi-圖像分辨率,默認(rèn)144 filter_column_colors=True,#去除條形圖重復(fù)顏色,True去除,默認(rèn)為False )
這里展示的是App近一年的月收入排行前十流水線。
二.近一月日收入可視化
2.1獲取數(shù)據(jù)
###王者榮耀近一個(gè)月日收入 def near_month(): url = "https://api.qimai.cn/pred/revenue?analysis=dQ51TyxjAEd9WQBJdg5%2BTylecxV9dH1EfVpTDStzU1Z6TCwFflpiWlJXBVl3G0tERARUH0JVRlVeTQF3G1UEB1YJBQQJBgAECyQUCQ%3D%3D&appid=989673964&country=cn&sdate=2021-02-26&edate=2021-03-27" response = requests.post(url, headers=headers) text = json.loads(response.text) data_list = text['data']['list'] name=[] value=[] for i in range(len(data_list)-1,-1,-1): name.append(todate(str(data_list[i][0])[0:-3])) value.append(data_list[i][1])
上圖紅框中是時(shí)間戳,需要轉(zhuǎn)為日期,比如1616774400000轉(zhuǎn)為2021-3-27
###時(shí)間戳轉(zhuǎn)為字符串 def todate(timeStamp): timeStamp = int(timeStamp) timeArray = time.localtime(timeStamp) # 將時(shí)間戳轉(zhuǎn)換成元組對(duì)象 time_str = time.strftime('%Y-%m-%d', timeArray) # 將元組轉(zhuǎn)換成對(duì)應(yīng)的時(shí)間格式 return time_str
2.2可視化展示
###拉伸圖 from pyecharts import options as opts from pyecharts.globals import ThemeType from pyecharts.charts import Bar def silder(name,value): c = ( Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK)) .add_xaxis(xaxis_data=name) .add_yaxis("日收入/美元", yaxis_data=value) .set_global_opts( title_opts=opts.TitleOpts(title="王者榮耀近一個(gè)月日收入情況"), datazoom_opts=[opts.DataZoomOpts(), opts.DataZoomOpts(type_="inside")], ) .render("王者榮耀近一個(gè)月日收入情況.html") )
三.近一年月收入可視化
3.1獲取數(shù)據(jù)
數(shù)據(jù)可以從csv中App收入排行_lyc.csv讀?。?/p>
f = open("App收入排行_lyc.csv",encoding="utf-8") content = f.read() rows = content.split('\n') name = rows[0].split(",")[1:] dict_values = rows[1].split(",")[1:]
3.2可視化展示
c = ( Bar( init_opts=opts.InitOpts( # 初始配置項(xiàng) theme=ThemeType.MACARONS, animation_opts=opts.AnimationOpts( animation_delay=1000, animation_easing="cubicOut" # 初始動(dòng)畫延遲和緩動(dòng)效果 )) ) .add_xaxis(xaxis_data=name) # x軸 .add_yaxis(series_name="王者榮耀近一年月收入情況", yaxis_data=dict_values) # y軸 .set_global_opts( title_opts=opts.TitleOpts(title='', subtitle='', # 標(biāo)題配置和調(diào)整位置 title_textstyle_opts=opts.TextStyleOpts( font_family='SimHei', font_size=25, font_weight='bold', color='red', ), pos_left="90%", pos_top="10", ), xaxis_opts=opts.AxisOpts(name='月份', axislabel_opts=opts.LabelOpts(rotate=45)), # 設(shè)置x名稱和Label rotate解決標(biāo)簽名字過長使用 yaxis_opts=opts.AxisOpts(name='月收入/美元'), ) .render("王者榮耀近一年月收入情況.html") )
到此這篇關(guān)于教你如何用python爬取王者榮耀月收入流水線的文章就介紹到這了,更多相關(guān)python爬取王者榮耀月流水線內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python表格數(shù)據(jù)處理庫之tablib庫詳解
這篇文章主要介紹了Python表格數(shù)據(jù)處理庫之tablib庫詳解,Tablib是一個(gè)用于處理電子表格數(shù)據(jù)的Python庫,它可以輕松地進(jìn)行數(shù)據(jù)的導(dǎo)入和導(dǎo)出,以及數(shù)據(jù)格式的轉(zhuǎn)換,需要的朋友可以參考下2023-08-08Python實(shí)現(xiàn)時(shí)鐘顯示效果思路詳解
這篇文章主要介紹了Python實(shí)現(xiàn)時(shí)鐘顯示,需要的朋友可以參考下2018-04-04Python基于隨機(jī)采樣一至性實(shí)現(xiàn)擬合橢圓
這篇文章主要為大家詳細(xì)介紹了Python如何基于隨機(jī)采樣一至性實(shí)現(xiàn)擬合橢圓,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的可以了解一下2022-11-11Python入門之三角函數(shù)atan2()函數(shù)詳解
這篇文章主要介紹了Python入門之三角函數(shù)atan2()函數(shù)詳解,分享了其實(shí)例,具有一定參考價(jià)值,需要的朋友可以了解下。2017-11-11