?最近常聽到說女生的A罩杯,穿衣百搭且很高級!
今天,我們就爬取京東商城某文胸品牌不同size的大致銷售情況,來看看當前什么尺碼才是主流吧!
目錄
1. 需求梳理
2. 資料采集
3. 統計展示
3.1. cup分布
3.2. color分布
4. 就這樣吧
5. Python學習資源
?
1. 需求梳理
很多人學習蟒蛇,不知道從何學起,
很多人學習尋找python,掌握了基本語法之后,不知道在哪里案例上手,
很多已經可能知道案例的人,卻不怎么去學習更多高深的知識,
這三類人,我給大家提供一個好的學習平臺,免費獲取視頻教程,電子書,以及課程的源代碼!
QQ群:101677771
歡迎加入,一起討論學習
本文比較簡單,單純對京東評論數最多的某文胸品牌不同size的商品評論數進行采集,然后統計出不同size的占比,
由于京東沒有類似銷量(或多少人付款)等資料,我們這里僅用評論數做對比維度,關于評論數的獲取,我們這里就不展開介紹了,
通過在京東進行商品型別選擇內衣-文胸-適用人群 青年,再按照評論數排序,我們可以得到排名靠前的商品串列,由于前2個都是均碼無尺寸的,第3個是文胸洗衣袋(也是均碼無尺寸),故而我們選擇了第4個商品,
?
尋找目標品牌
然后,我們直接點擊進入到第4個商品的詳情頁面,發現存在很多7種顏色和10種尺寸,這組合有點多啊,
為了更好的獲取每件商品的評論資料,我們這里需要先獲取每個商品的productId,于是,我們F12進入到開發者模式,在元素頁搜索其中一個商品id最終發現了存放全部商品id的地方如下:(可以通過正則決議出來)
color&size
既然可以獲取全部的商品id,那么通過商品id即可呼叫評論介面獲取對應商品的評論資料了,我們就編碼走起!
?
2. 資料采集
資料采集部分,先用正則獲取全部的商品id,然后通過商品id獲取全部商品id對應的評論資料,那么需要的資料就齊活了,
獲取全部商品id
import requests
import re
import pandas as pd
headers = {
# "Accept-Encoding": "Gzip", # 使用gzip壓縮傳輸資料讓訪問更快
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
# "Cookie": cookie,
"Referer": "https://item.jd.com/"
}
url= r'https://item.jd.com/100003749316.html'
r = requests.get(url, headers=headers, timeout=6)
text = re.sub(r'\s','',r.text)
colorSize = eval(re.findall(r'colorSize:(\[.*?\])', text)[0])
df = pd.DataFrame(colorSize)
?
獲取商品id對應評論資料
# 獲取評論資訊
def get_comment(productId, proxies=None):
# time.sleep(0.5)
url = 'https://club.jd.com/comment/skuProductPageComments.action?'
params = {
'callback': 'fetchJSON_comment98',
'productId': productId,
'score': 0,
'sortType': 6,
'page': 0,
'pageSize': 10,
'isShadowSku': 0,
'fold': 1,
}
# print(proxies)
r = requests.get(url, headers=headers, params=params,
proxies=proxies,
timeout=6)
comment_data = https://www.cnblogs.com/sn5200/p/re.findall(r'fetchJSON_comment98\((.*)\)', r.text)[0]
comment_data = https://www.cnblogs.com/sn5200/p/json.loads(comment_data)
comment_summary = comment_data['productCommentSummary']
return sum([comment_summary[f'score{i}Count'] for i in range(1,6)])
df_commentCount = pd.DataFrame(columns=['skuId','commentCount'])
proxies = get_proxies()
for productId in df.skuId[44:]:
df_commentCount = df_commentCount.append({
"skuId": productId,
"commentCount": get_comment(productId, proxies),
},
ignore_index=True
)
df = df.merge(df_commentCount,how='left')
?
3. 統計展示
我們先將尺碼中的ABC..罩杯部分單獨成列
df['cup'] = df['尺碼'].str[-1]
開始我們的簡單統計展示吧
先看資料資訊概況
>>> df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 64 entries, 0 to 63
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 尺碼 64 non-null object
1 skuId 64 non-null object
2 顏色 64 non-null object
3 commentCount 64 non-null object
4 cup 64 non-null object
dtypes: object(5)
memory usage: 3.0+ KB
3.1. cup分布
不過我們采集的資料中只劃分了A-B-C三種cup,,
cupNum = df.groupby('cup')['commentCount'].sum().to_frame('數量')
cupNum
|
cup |
數量 |
|
A |
6049 |
|
B |
11618 |
|
C |
4076 |
import matplotlib.pyplot as plt
from matplotlib import font_manager as fm
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
plt.rcParams['axes.unicode_minus'] = False
labels = cupNum.index
sizes = cupNum['數量']
explode = (0, 0.1, 0)
fig1, ax1 = plt.subplots(figsize=(6,5))
patches, texts, autotexts = ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
ax1.axis('equal')
# 重新設定字體大小
proptease = fm.FontProperties()
proptease.set_size('large')
plt.setp(autotexts, fontproperties=proptease)
plt.setp(texts, fontproperties=proptease)
ax1.set_title('cup 分布')
plt.show()
?
cup分布
我們可以看到,高達53.4%的買家是B-cup,其次才是A-cup占比27.8%,
3.2. color分布
colorNum = df.groupby('顏色')['commentCount'].sum().to_frame('數量')
colorNum
|
顏色 |
數量 |
|
淺膚 |
3627 |
|
淡藍灰 |
3058 |
|
淡銀灰 |
3837 |
|
白色 |
1439 |
|
藕粉 |
8286 |
|
酒紅 |
1429 |
|
黑色 |
67 |
我們可以看到,藕粉色最多而且遙遙領先,其次是淡銀灰、淺膚和淡藍色,
?
color分布
以下是占比最高高達38.1%的藕粉色
?
藕粉色:來自京東
?
4. 就這樣吧
我們看到最多的34/75B,34就是英碼對照,75可以理解為下胸圍長(其實這里的34和75可以理解為一樣的含義),B則是cup,
關于cup和胸圍對照表,參考:
?
以上就是本次全部內容,樣本量較小,不做考究,僅供娛樂哈!?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/415224.html
標籤:Python
上一篇:python錯誤與例外
