教你如何用python爬取王者榮耀月收入流水線
前言
王者榮耀是最近幾年包括現(xiàn)在一直都是最熱銷的手游,收益主要來源是游戲里面人物皮膚。今天就來爬取展示王者榮耀近一年收入流水線動圖,看看王者榮耀有多賺錢(哈哈哈哈)
主要可視化內容:
一.App收入排行流水線
1.1.獲取數(shù)據(jù)
數(shù)據(jù)來源于:七麥數(shù)據(jù),里面數(shù)據(jù)都是通過異步加載,因此只需要找到異步鏈接,修改參數(shù)就可以直接獲取到數(shù)據(jù)。
備注:需要cookie才可以獲取數(shù)據(jù)。
請求鏈接
https://api.qimai.cn/pred/appMonthPred?analysis=eEcbRhNVVB9RQEB9VwpDUDRGUwVwEwEAAQcIClwODlQEAyETAQ%3D%3D
請求參數(shù)
data = { 'device': 'iphone', 'genre': 36, 'month': date[d], }
請求數(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ù)臨時保存到字典中
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'] #顯示中文標簽 plt.rcParams['axes.unicode_minus']=False #解決負號“-”顯示為方塊的問題 # 獲取數(shù)據(jù) df = pd.read_csv("App收入排行_lyc.csv",index_col=0) # 生成動態(tài)流水線 bcr.bar_chart_race(df=df, filename='App收入排行_lyc.mp4', #生成的動態(tài)條形圖的文件位置 orientation='h', #h條形圖 v柱狀圖 sort='desc', #降序,asc-升序 n_bars=10, #設置最多能顯示的條目數(shù) fixed_order=False, # 設置固定類目 fixed_max=False, #固定數(shù)值軸,使其不發(fā)生動態(tài)變化 True-固定 steps_per_period=24, #圖像幀數(shù):數(shù)值越小,越不流暢,越大,越流暢 period_length=20, #設置幀率,單位時間默認為500ms 即為24幀的總時間是500ms end_period_pause=0,#固定值比如年份的停留時間 interpolate_period=False, period_label={'x': .80, 'y': .5, 'ha': 'right', 'va': 'center','size':16}, #設置日期標簽的時間格式 colors='dark12', #設置柱狀圖顏色顏色,通過在「_colormaps.py」文件中添加顏色信息,即可自定義配置顏色 title={'label': 'App收入排行_lyc','size': 18,}, #圖表標題 bar_size=.95, #條形圖高度 bar_textposition='inside',#條形圖標簽文字位置 bar_texttemplate='{x:,.0f}', #條形圖標簽文字格式 bar_label_font=16, #條形圖標簽文字大小 tick_label_font=16, #坐標軸標簽文字大小 tick_template='{x:,.0f}',#坐標軸標簽文字格式 shared_fontdict={'family': 'Microsoft YaHei','color': 'rebeccapurple'}, #全局字體屬性 scale='linear', fig=None, writer=None, bar_kwargs={'alpha': .7},#條形圖屬性,可以設置透明度,邊框等 fig_kwargs={'figsize': (16, 10), 'dpi': 144},#figsize-設置畫布大小,默認(6, 3.5),dpi-圖像分辨率,默認144 filter_column_colors=True,#去除條形圖重復顏色,True去除,默認為False )
這里展示的是App近一年的月收入排行前十流水線。
二.近一月日收入可視化
2.1獲取數(shù)據(jù)
###王者榮耀近一個月日收入 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])
上圖紅框中是時間戳,需要轉為日期,比如1616774400000轉為2021-3-27
###時間戳轉為字符串 def todate(timeStamp): timeStamp = int(timeStamp) timeArray = time.localtime(timeStamp) # 將時間戳轉換成元組對象 time_str = time.strftime('%Y-%m-%d', timeArray) # 將元組轉換成對應的時間格式 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="王者榮耀近一個月日收入情況"), datazoom_opts=[opts.DataZoomOpts(), opts.DataZoomOpts(type_="inside")], ) .render("王者榮耀近一個月日收入情況.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( # 初始配置項 theme=ThemeType.MACARONS, animation_opts=opts.AnimationOpts( animation_delay=1000, animation_easing="cubicOut" # 初始動畫延遲和緩動效果 )) ) .add_xaxis(xaxis_data=name) # x軸 .add_yaxis(series_name="王者榮耀近一年月收入情況", yaxis_data=dict_values) # y軸 .set_global_opts( title_opts=opts.TitleOpts(title='', subtitle='', # 標題配置和調整位置 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)), # 設置x名稱和Label rotate解決標簽名字過長使用 yaxis_opts=opts.AxisOpts(name='月收入/美元'), ) .render("王者榮耀近一年月收入情況.html") )
到此這篇關于教你如何用python爬取王者榮耀月收入流水線的文章就介紹到這了,更多相關python爬取王者榮耀月流水線內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Python表格數(shù)據(jù)處理庫之tablib庫詳解
這篇文章主要介紹了Python表格數(shù)據(jù)處理庫之tablib庫詳解,Tablib是一個用于處理電子表格數(shù)據(jù)的Python庫,它可以輕松地進行數(shù)據(jù)的導入和導出,以及數(shù)據(jù)格式的轉換,需要的朋友可以參考下2023-08-08Python入門之三角函數(shù)atan2()函數(shù)詳解
這篇文章主要介紹了Python入門之三角函數(shù)atan2()函數(shù)詳解,分享了其實例,具有一定參考價值,需要的朋友可以了解下。2017-11-11