隔幾天就能看到瑞幸燒錢摔刁、虧損挥转,活不長的消息滿屏飛。友情提示:
技術流文章钞支,文科生請繞道郊楣,以免燒腦。
既然有免費贈送體驗券共屈,那咱肯定要去試一試對不對绑谣。萬一哪天就不送了呢。
說干就干拗引,抓取手機借宵、搜下瑞幸的微信小程序,輸入下手機號碼就注冊好了矾削,挺便捷的壤玫。完成后就收到一堆優(yōu)惠券了。
有券任性哼凯,開始買買買:
第一杯欲间,焦糖瑪奇朵半糖,不知道是糖太少還是奶蓋太少断部,又苦又澀猎贴,說實話真不懂,跟以往其他奶茶店喝的焦糖瑪奇朵比起來是完全不同蝴光,我都懷疑喝的是假咖啡她渴;
第二杯,百香芒果瑞納冰虱疏;第三杯惹骂,抹茶拿鐵;第四杯做瞪,NFC鮮榨藍莓草莓混合果汁对粪,感覺都還也不錯啊,原諒我讀書少剛開始不知道NFC代表啥装蓬,難道是像手機那樣的刷公交卡著拭。幾個人買幾瓶可以在那滴滴滴互動?淘寶上搜了下牍帚,才發(fā)現是學名是“非濃縮還原汁”儡遮,繞這么大一圈。公司里很多小姐姐超喜歡這款暗赶,預計會火鄙币。然后接著第五肃叶、六、七杯都還不錯十嘿,沒網上看到說的那么不堪因惭。
為了證明這個結論,上爬蟲到微博抓取些評論來做下情感評論分析绩衷,對于瑞幸的評論好不好蹦魔,讓大眾評價說話。
1咳燕、爬蟲抓取微博關鍵詞"瑞幸"評論
循環(huán)翻頁爬取關于瑞幸的所有評論內容勿决。結果存入excel,待查看評價內容招盲,讀取后做情感評價分析低缩。
#微博爬蟲:https://s.weibo.com/,按“瑞幸”搜索
from selenium import webdriver
from lxml import etree
import time,datetime,xlwt,xlrd,os,re
from xlutils.copy import copy
from urllib import parse
def parse_time(time_str):
if '分鐘前' in time_str:
time_temp = int(time_str.split('分鐘前')[0])
new_time = (datetime.datetime.now() + datetime.timedelta(minutes=time_temp)).strftime("%Y-%m-%d %H:%M")
elif '今天' in time_str:
time_temp = time_str.split('今天')[1]
new_time = (datetime.datetime.now()).strftime("%Y-%m-%d") + ' ' +time_temp
elif '月' in time_str and '日' in time_str:
time_temp = time_str.replace('月','-').replace('日','-')
new_time = (datetime.datetime.now()).strftime("%Y") + '-' +time_temp
else:
new_time=''
return new_time
# 創(chuàng)建excel表
def create_wookbook(sheetheader):
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('weibo')
# 寫入表頭
for h in range(0, len(sheetheader)):
worksheet.write(0, h, sheetheader[h])
workbook.save('weibo.xls')
# 寫入數據
def write_into_workbook(rows, content_info_list):
oldWb = xlrd.open_workbook('weibo.xls') # 先打開已存在的表
newWb = copy(oldWb) # 復制
newWs = newWb.get_sheet(0) # 取sheet表
for ex in content_info_list:
for col in range(0, len(ex)):
newWs.write(rows, col, ex[col])
rows += 1
newWb.save('weibo.xls')
return rows
def weibo(key_word,user_name,user_key,pages):
dict_weibo ={'q':key_word,'wvr':'6','b':'1','Refer':'SWeibo_box'}
print('采集關鍵詞:{},采集頁數:{}'.format(key_word,pages))
start_url = 'https://s.weibo.com/weibo?'+parse.urlencode(dict_weibo)
sheetheader = ['編號', '用戶名', '用戶鏈接', '會員類型', '評論內容', '評論時間', '來自','轉發(fā)','評論','點贊']
if not os.path.exists('weibo.xls'):
create_wookbook(sheetheader)
rows =1
driver = webdriver.Chrome()
driver.get('https://s.weibo.com/')
time.sleep(2)
html = etree.HTML(driver.page_source)
if html.xpath('//*[@id="weibo_top_public"]/div/div/div[3]/div[2]/ul/li[3]/a'):
driver.find_element_by_xpath('//*[@id="weibo_top_public"]/div/div/div[3]/div[2]/ul/li[3]/a').click()
time.sleep(2)
input_user = driver.find_element_by_xpath('.//input[@action-data="text=郵箱/會員帳號/手機號"]')
time.sleep(2)
input_user.clear()
input_user.send_keys(user_name)#輸入賬號
time.sleep(2)
input_key = driver.find_element_by_xpath('.//input[@type="password"]')
input_key.clear()
input_key.send_keys(user_key)#輸入密碼
driver.find_element_by_xpath('.//span[@class="enter_psw"]/../../div[@class="item_btn"]/a').click() #點擊登錄
time.sleep(2)
for page in range(1,pages+1):
url = (start_url+'&page={}').format(page)
driver.get(url)
html = etree.HTML(driver.page_source)
item = html.xpath('.//div[@class="card-wrap" and @action-type="feed_list_item"]')
content_info = {}
content_info_list = []
for i in item:
# content_info['page'] = page
content_info['mid'] = "".join(i.xpath('./@mid')).strip()
content_info['user_name'] = "".join(i.xpath('.//descendant::div[@class="content"]/div/div/a[@class="name"]/@nick-name')).strip()
content_info['user_link'] = 'https:'+"".join(i.xpath('.//descendant::div[@class="content"]/div/div/a[@class="name"]/@href')).strip().split('?re')[0]
content_info['user_type'] = "".join(i.xpath('.//descendant::div[@class="content"]/div/div/a[@target="_blank" and @title]/@title')).strip()
content_info['content_txt'] = "".join(i.xpath('.//descendant::div[@class="content"]/p[@class="txt"][position()=last()]//text()')).strip()
content_info['content_time'] = "".join(i.xpath('.//descendant::div[@class="content"]/p[@class="from"]/a[@suda-data]/text()')).strip()
if content_info['content_time'] == '':
content_info['content_time'] = ''
else:
content_info['content_time'] = parse_time(content_info['content_time'])
content_info['phone_nofollow'] = "".join(i.xpath('.//descendant::div[@class="content"]/p[@class="from"]/a[@rel="nofollow"]/text()')).strip()
content_info['content_zhuanfa'] = "".join(i.xpath('.//descendant::div[@class="card-act"]/ul/li[2]//text()')).strip().replace('轉發(fā)','')
content_info['content_pinglu'] = "".join(i.xpath('.//descendant::div[@class="card-act"]/ul/li[3]//text()')).strip().replace('評論','')
content_info['content_dianzan'] = "".join(i.xpath('.//descendant::div[@class="card-act"]/ul/li[4]//text()')).strip().replace('贊','')
content_info_list.append(list(content_info.values()))
print(content_info_list)
rows = write_into_workbook(rows, content_info_list)
time.sleep(2)
print('采集完成')
driver.close()
if __name__ =='__main__':
key_word = input('請輸入采集關鍵詞:')
user_name = input('請輸入微博用戶名:')
user_key = input('請輸入微博密碼:')
pages = 50 #采集頁數
weibo(key_word,user_name,user_key,pages)
2、讀取評價列表宪肖,調用百度情感評價api分析每一條評價得分
#情感評分分析
from aip import AipNlp
import csv,re
import pandas as pd
import numpy as np
""" 你的 APPID AK SK """
# 利用百度云提供的API接口實現情感分析
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
client = AipNlp(APP_ID, API_KEY, SECRET_KEY)
#清洗Unicode編碼字符串http://www.reibang.com/p/4958bcdea12a
def illegal_char(s):
s = re.compile( \
u"[^"
u"\u4e00-\u9fa5"
u"\u0041-\u005A"
u"\u0061-\u007A"
u"\u0030-\u0039"
u"\u3002\uFF1F\uFF01\uFF0C\u3001\uFF1B\uFF1A\u300C\u300D\u300E\u300F\u2018\u2019\u201C\u201D\uFF08\uFF09\u3014\u3015\u3010\u3011\u2014\u2026\u2013\uFF0E\u300A\u300B\u3008\u3009"
u"\!\@\#\$\%\^\&\*\(\)\-\=\[\]\{\}\\\|\;\'\:\"\,\.\/\<\>\?\/\*\+"
u"]+").sub('', s)
return s
# 對讀入的數據進行情感分析表制,將其得到的結果解析成標準JSON格式數據健爬,并保存在一個新的dict中
def senti_anlaly(text):
text = illegal_char(text)
data = client.sentimentClassify(text)
sentiment =data['items'][0]['positive_prob']
return sentiment
datas = pd.read_excel('weibo_luckin.xls',sheet_name='weibo',header=0,encoding = "gbk")
sentiments = []
for s in list(datas['評論內容']):
sentiments.append(senti_anlaly(s))
3控乾、分析情感評價得分
評價平均分、中位數:
print('情感評分平均得分:'+str(np.mean(sentiments)))
print('情感評分中位數:'+str(np.median(sentiments)))
情感評分平均得分:0.697娜遵;情感評分中位數:0.806
直方圖分布:
from matplotlib import pyplot
import math
grades =[]
for s in sentiments:
grades.append(math.ceil(s*10)/10)
#繪制直方圖
def drawHist(sentiments):
#創(chuàng)建直方圖
#第一個參數為待繪制的定量數據蜕衡,不同于定性數據,這里并沒有事先進行頻數統(tǒng)計
#第二個參數為劃分的區(qū)間個數
x =[i/10 for i in range(1,11,1)]
pyplot.hist(sentiments, 10)
pyplot.xticks(x)
pyplot.xlabel('score')
pyplot.ylabel('Frequency')
pyplot.title('luckin weibo sentiment score')
pyplot.figure(figsize=(12, 12))
pyplot.show()
drawHist(grades)
按0.1等間距劃分分布设拟,可以很明顯的看到情感評分得分集中分布在0.7-1分慨仿,且0.9-1分數量還是最多的,超過300個纳胧,將近1/3(因微博只能查看前50頁镰吆,只能爬1000條數據)。
累計柱形圖:
from matplotlib import pyplot
#繪制累積曲線
def drawCumulativeHist(sentiments):
#創(chuàng)建累積曲線
#第一個參數為待繪制的定量數據
#第二個參數為劃分的區(qū)間個數
#normed參數為是否無量綱化
#histtype參數為'step'跑慕,繪制階梯狀的曲線
#cumulative參數為是否累積
x =[i/10 for i in range(1,11,1)]
pyplot.hist(sentiments, 10, normed=True, histtype='step', cumulative=True)
pyplot.xticks(x)
pyplot.xlabel('score')
pyplot.ylabel('Frequency')
pyplot.title('luckin weibo sentiment score')
pyplot.show()
drawCumulativeHist(grades)
累計柱形圖中:0.7分以上占了60%万皿。
百度的這個情感傾向分析,0.5-0.7有一些誤判的核行,明明是負向的牢硅,評到了0.6-0.7幾。但是0.8以上基本誤判的就比較少了芝雪,加上有些高分誤判到低分的减余。相互抵消下,這個情感傾向評分結果是很有具有說服力的惩系。
直觀的數據結果位岔,會出乎大多數人意外如筛。瑞幸,其實比你想象中的要好抒抬。
網上關于瑞幸的負面評價妙黍,大多數是有失公允的。如果再去看下負面評價的來源瞧剖,大多是營銷號在帶節(jié)奏拭嫁。
把瑞幸類比ofo的,其實也是站不住腳的抓于,ofo沒騎兩三次就壞了做粤,大量的虧損至破產來源小黃車的損壞。而瑞幸店面會壞嗎捉撮?還是瑞幸服務員會壞怕品?
瑞幸更像的是滴滴模式,虧損來源于前期獲取用戶的補貼巾遭,0元免費送一杯肉康、2.8折一杯、以及一堆5折券灼舍、去年的買一送二吼和、買五送五等活動。
http://dy.163.com/v2/article/detail/EDELPID30511WT04.html
看下剛公布的幾個數據
(連星巴克的股東都跑來投資瑞幸了)
瑞幸到2019Q1累計虧損21.7億骑素,用戶數1687萬炫乓。實際上虧損來源于新客補貼、大量買一送二献丑、累計抽紅包等活動末捣。等新用戶數增長到一定數量,新客變老客创橄,瑞幸自然也不需要再花那么大的價錢獲取新客了箩做。
今年新客成本降到16.9元,這個數字很值得推敲妥畏,因為今年注冊新用戶的優(yōu)惠券是:0元免費送邦邦、2.8折、以及一堆5折券咖熟。會讓瑞幸虧損的最多的是0元免費送一杯圃酵、2.8折一杯送的。假設獲客成本都是0元馍管、2.8折來的郭赐,平均一杯虧:16.9/(1+(1-0.28))=9.8元,就是說一杯成本才10元左右(如果5折里還有獲客成本,那單杯成本就是16.9/(1+(1-0.28)+n0+n1+……)捌锭,成本還要更低)俘陷。瑞幸咖啡、飲料售價在24-27观谦,即使按5折售賣拉盾,也大概就能盈虧平衡了。
http://www.luckinjm.com/news/22.html(瑞幸官網上自己公布的數據豁状,算完才找到的-_-|||捉偏,扣掉租金、設備折舊泻红、人工(北京比較貴)夭禽、水電,跟上面算出的9.8接近谊路。)