双节期间月饼价格

10月3日数据如下:

京东

京东总共爬取了662件商品的数据,其中77条数据重复。商品平均价格为60元(四舍五入),最低价格为9.9元(一品粤广式月饼散装多口味广东老式传统中秋节送礼手工单独立包装单个装 蛋黄莲蓉125g*1个)(御茶膳房月饼礼盒中秋节送礼高端礼品广式莲蓉蛋黄五仁火腿奶黄月饼1470g)(美心(Mexin)代购 美心流心奶黄月饼360g(45g*8)礼盒装)并列最高价498元。

较两个月前平均价上涨7元,最低价上涨8元,最高价未变。

淘宝

淘宝总共爬取了481件商品的数据,其中34条数据重复。商品平均价格为12元(四舍五入),最低价格为2元(卢师傅椰蓉月饼散装花生酥老五仁红豆多口味中秋节糕点小零食酥皮)最高价格为253元(新疆盼月坚果仁月饼中秋节大月饼一个装送礼传统老式手工糕点零食)

较两个月前平均价上涨3元,最低价上涨0.2元,最高价上涨121元。

京东

爬取京东前10页月饼的价格,总共爬取了600件商品的数据,其中73条数据重复。商品平均价格为53元(四舍五入),最低价格为1.99元(散装40g单个)最高价498元(礼盒装45g*8)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import csv

# 页面下滑
def drop_down():
driver.execute_script("document.documentElement. scrollTop=100000")
time.sleep(2)

def get_shop_info():
# 延时,等待页面加载完成
time.sleep(2)
driver.implicitly_wait(10) # 隐式等待
drop_down()
lis = driver.find_elements(By.CLASS_NAME, "gl-item")
print(lis)
for li in lis:
title = li.find_element(By.CSS_SELECTOR, ".p-name-type-2 em").text
price = li.find_element(By.CSS_SELECTOR, ".p-price strong i").text
commit = li.find_element(By.CSS_SELECTOR, ".p-commit strong a").text
href = li.find_element(By.CSS_SELECTOR, ".p-img a").get_attribute("href")
# 保存数据
dict = {
"标题": title,
"价格": price,
"评论数": commit,
"详情页": href,
}
csv_writer.writerow(dict)
print(title, price, href)
time.sleep(2)
# 点击下一页
driver.find_element(By.CLASS_NAME, "pn-next").click()

# 创建文件
# f = open("月饼.csv", mode="a", encoding="utf-8", newline="") # encoding="utf-8"用excel打开会乱码
f = open("月饼-京东.csv", mode="a", newline="") # 不加encoding="utf-8"用excel打开正常,但记事本打开会乱码
# 字典写入
csv_writer = csv.DictWriter(f, fieldnames=[
"标题",
"价格",
"评论数",
"详情页",
])
# 写入表头
csv_writer.writeheader()

driver = webdriver.Chrome()
# driver = webdriver.Firefox()
driver.get('https://www.jd.com')
driver.find_element("id", "key").send_keys("月饼")
driver.find_element(By.CLASS_NAME, "button").click()
driver.implicitly_wait(10) # 隐式等待

for page in range(1, 11):
print(f"正在采集第{page}页的内容")
get_shop_info()

部分数据如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
滇园滇式云腿月饼50g*10枚便携盒装,39.80,2万+,https://item.jd.com/15272527664.html
杏花楼 玫瑰豆沙月饼 中华老字号上海特产 广式月饼中秋传统散装 100g,10.50,20万+,https://item.jd.com/100024850829.html
日月坊 月饼广式老五仁中秋手工饼2斤 五仁月饼10个两斤装,18.80,2000+,https://item.jd.com/10056245302817.html
杏花楼 蛋黄莲蓉月饼 中华老字号上海特产 广式月饼中秋传统散装 100g,11.50,20万+,https://item.jd.com/100024850841.html
春江月 五仁月饼 东北老式月饼 传统月饼 京式月饼 中秋团购员工福利 400g,26.80,2万+,https://item.jd.com/100021468630.html

......

华情 广东吴川手工伍仁金腿大月饼1斤装五仁火腿广式肉松月饼500g单个,98.00,46,https://item.jd.com/10055689667814.html
福隆祥老式五仁月饼苏式酥皮多口味传统手工老式中秋月饼团购60g/个 酥皮老伍仁24个,46.00,5000+,https://item.jd.com/10034284297829.html
韩小欠蛋月烧甜点五仁枣肉口味80g营养香味浓郁软糯传统月饼 枣肉味 80g 5块,31.90,73,https://item.jd.com/10071935093002.html
公主店下五仁莲蓉豆沙小月饼点心零食糕点 豆沙馅50g/个 1斤装,15.90,11,https://item.jd.com/10075853312013.html
浙江温州桥墩月饼老式传统正宗周兴豪中秋大月饼一个装员工团购批发 500克蛋黄,38.00,100+,https://item.jd.com/10055542757139.html

淘宝

爬取淘宝前10页月饼的价格,总共爬取了471件商品的数据,其中79条数据重复。商品平均价格为9元(四舍五入),数据最低价格为0.75元(单个月饼盒,非月饼)最低价格为1.8元(单个月饼)最高价132元(礼盒装5斤)

淘宝的反爬机制比京东更严格,用selenium打开淘宝商品页和手动打开淘宝商品页相应标签的class属性值有时一样,有时不一样。其次,淘宝的价格相比京东更不真实,搜索结果页面只显示商品的最低价,这样就爬不到商品的最高价了,详情页面里不同月饼的价格相差很大,实际价格是多个固定值组成的区间。因此,淘宝的数据没法算出平均价格,只能算出最低平均价格。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import csv

# 隐藏selenium基本信息
options = webdriver.ChromeOptions()
# 禁用自动化栏
options.add_experimental_option("excludeSwitches", ["enable-automation"])
# 屏蔽保存密码提示框
prefs = {"credentials_enable_service": False, "profile.password_manager_enabled": False}
options.add_experimental_option("prefs", prefs)
# 反爬虫特征处理
options.add_argument("--disable-blink-features=AutomationControlled")

driver = webdriver.Chrome(options=options)
url = "https://www.taobao.com/"
driver.get(url)
driver.find_element("id", "q").send_keys("月饼")
driver.find_element(By.CLASS_NAME, "btn-search").click()
driver.implicitly_wait(20) # 隐式等待

try:
driver.find_element(By.CSS_SELECTOR, "#fm-login-id").send_keys("18770857191")
driver.find_element(By.CSS_SELECTOR, "#fm-login-password").send_keys("18770857191-FKP")
time.sleep(3)
except:
print("无法登录")

"""滑块验证"""
try:
# 进入嵌套页面
driver.switch_to.frame(0)
# 定位小滑块
slider = driver.find_element(By.CSS_SELECTOR, "#nc_1_n1z")
# 持续按住滑块
webdriver.ActionChains.click_and_hold(on_element=slider).perform()
# 横向移动鼠标
webdriver.ActionChains(driver).move_by_offset(xoffset=260, yoffset=0).perform()
# 松开鼠标
webdriver.ActionChains(driver).pause(0.5).release().perform()
# 回到主页面
driver.switch_to.parent_frame()
except:
print("没有滑块")

try:
driver.find_element(By.CSS_SELECTOR, "#login-form > div.fm-btn > button").click()
except:
print("没有登录按钮")

# 创建文件
f = open("月饼-淘宝.csv", mode="a", newline="") # 不加encoding="utf-8"用excel打开正常,但记事本打开会乱码
# f = open("粽子-淘宝2.csv", mode="a", encoding="ANSI", newline="") # 不加encoding="utf-8"时默认ANSI编码
# f = open("粽子-淘宝2.scv", mode="a", encoding="utf-8", newline="")
# 字典写入
csv_writer = csv.DictWriter(f, fieldnames=[
"商品",
"价格",
"地区",
"购买人数",
"店铺名",
"详情页",
])
# 写入表头
csv_writer.writeheader()

def good_info():
time.sleep(2)
items = driver.find_elements(By.CLASS_NAME, "Card--doubleCardWrapper--L2XFE73")
# print(items)
for item in items:
good = item.find_element(By.CSS_SELECTOR, ".Title--title--jCOPvpf").text
price = item.find_element(By.CSS_SELECTOR, ".Price--priceWrapper--Q0Dn7pN .Price--priceInt--ZlsSi_M").text
area = item.find_element(By.CSS_SELECTOR, ".Price--priceWrapper--Q0Dn7pN .Price--procity--_7Vt3mX").text
people = item.find_element(By.CSS_SELECTOR, ".Price--priceWrapper--Q0Dn7pN .Price--realSales--FhTZc7U").text
store = item.find_element(By.CSS_SELECTOR, ".ShopInfo--shopName--rg6mGmy").text
href = item.get_attribute("href")

# 保存数据
dict = {
"商品": good,
"价格": price,
"地区": area,
"购买人数": people,
"店铺名": store,
"详情页": href,
}
csv_writer.writerow(dict)

print(good, price, people, area, store)

time.sleep(2)
# 点击下一页
driver.find_element(By.CLASS_NAME, "next-pagination-icon-next").click()

for page in range(1, 11):
print(f"正在采集第{page}页的内容")
good_info()

部分数据如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
经典美食老五仁月饼多口味酥皮月饼传统手工老式中秋月饼礼盒,7,山东,1000+人付款,巧媳妇美食店,https://click.simba.taobao.com/cc_im?p=%D4%C2%B1%FD&s=135287666&k=921&e=EFhUtssbHX9mNiWKd4YTZsKgUOQW6OrD%2FnI7GbypuYpL5JNBnWD9nyGd5z2Hj6pmZbMW%2FNHgUTxtHGvac19aXe%2BZvE30DSPZBLneF4CB45WhfaywJvC0RH5ITMtIpvGNwXJoYYre2V5QeEfUz4%2F2BYrJVKxfjtzbaWTeozxvVhadwEz%2FcuAkxNp5%2BL7ZzU3Fktfqucfht5fhu8vPw%2FSVcIJEGtsxwo2qzEg8l4oscsYEyUPbCOtzGBoZXLNTugL%2BC3j58gcUiemMyLt7BJTgksNz%2FsV1rfJgDkwWl4QCIi1No2kk67GjqTUYGjhjSoXYrQA8Y9cIQD4z9j40BfBM47TtWCRh9W2GLsLiiahqq8ifmvb0DoZmvpGl0dH3tg7bq3cCSf9WgRzX6R%2BXtF4YCS17jK7XDbgujXgqP1HzxuH4jcSR4xbRT8skfFdpRV0iX1HZEWdT0Pac0GukzayemOviftjtmAzqrUF9qWuujpJfBs7pQJQo6M33I2NFvnuehRam4wWbCTRQwGMYgC5Q1Sji1Enrl%2BAVJizWmPeMMAN074fvD%2FPd%2FWKtW5k3I%2FgNJsGk6Kzivh8rF1yRLSj4I6SCU7SeIyHK%2FrlKiuLFPCRZOTjrogMfIZkTMeNC6K2LntYF3MC13WN9fz2rGsjXfyaThIngMj%2BtnDP6fO7SJD3w425KCCKQ9kyByobm3bxVoyux%2FeVFmH2eTN4qFgqz50owIbKUboVN3HWRL4oC2OJKLpT84BqHN7qazdCMwiXoL312NjyKRNZQgnDGT6eWL%2BlpfF1nvf%2FMmyiW4o4Mx6mAkqTCa7wR4JhMYpbvUzVs%2BXPFiiQ%2FVGj%2Bf77QqMO58kz4yzLhpz0WfLSX%2FYYIUa7EmBrpGMsgrgnnLcOBRq2tnOASfXElR1X62MRAGFwDIQ%3D%3D#detail
日月坊月饼五仁月饼广式老式中秋节传统纯正宗手工字号散装多口味,88,山东,4000+人付款,日月坊旗舰店,https://click.simba.taobao.com/cc_im?p=%D4%C2%B1%FD&s=135287666&k=985&e=gL2uKa2yNbVmNiWKd4YTZsKgUOQW6OrD%2FnI7GbypuYpL5JNBnWD9nyGd5z2Hj6pmxkzzHrOu7sZEdYg40AoZmjCGr7LwS7%2BlBLneF4CB45WhfaywJvC0RH5ITMtIpvGNwXJoYYre2V5QeEfUz4%2F2BYrJVKxfjtzbaWTeozxvVhadwEz%2FcuAkxNp5%2BL7ZzU3Fktfqucfht5fhu8vPw%2FSVcIJEGtsxwo2qzEg8l4oscsYEyUPbCOtzGBoZXLNTugL%2BmkY9xxZjOQ5z9q2Bzpi4Fx7eAWzN0J7MEVxVlEGxOvhdFuiTUSZH%2FX8ppLld6cy49tDDZl5asP46QhK2akDRMOKiFHrjomZCSZRUiDUAcpOAnmmFLMxodZGl0dH3tg7bq3cCSf9WgRzX6R%2BXtF4YCXosO%2FICKQRTCkIBxcxgkgD4jcSR4xbRT1tY1pW1UODxrMls7RHPouf%2B6WOs9L%2FdLFCEKY1mZEkdjK03fiQjDXUmmky44XS%2Bay6nLHxXVVHyWjrEvvVHl51z9q2Bzpi4F2qLs29edzDIcisBBb3t3obNYd2rUpr7jnqlVNcxJxjsY78iyXwrLjyHQJuKPIxylDX3PqI7NpjU5E8kHM6gUVSH9v6RSB69Ja9TrdrfzDA8HTX8AHujtyLq%2Fs7%2FoEKdAvYD2ZE6e28Akflj4wZiydy2%2BAmz1TnlYs93%2BkadHfh5iT%2FTY2%2FhXQ9fnujpAcwlSiJyEXyokztVuNGgZobsTJDEWVK24TmFp1WKGPyYvqcYEbNtbW%2B7CmKV%2FlheMfDwaeVy7Up2xUP1BsAA8NpcLjBLakabTf6nJ55a%2Bk1kwmlY5NeEjXT6oLFdumGWMa4Vb6CxQ98HFly1qQEnq18EG%2F2ovEAlcYeSzXj0OmcPvM95aW29Wb%2B8cPG0EyrAVaeS2YTaTd1a9yseOAj%2FkZ4UU7SRMPIFERbrXPNM3W9Nwu8YoVMU0rdG%2FbdnaVZjV4u1GA%3D%3D
【好吃的秘密】老五仁大月饼多口味广式中秋月饼黑芝麻糕点零食,11,山东,1000+人付款,巧媳妇美食店,https://item.taobao.com/item.htm?id=700262081188&ns=1&abbucket=0#detail
五仁月饼广式老式中秋节传统纯正宗手工糕点零食伍仁礼盒装多口味,8,山东,800+人付款,妻之慧旗舰店,https://detail.tmall.com/item.htm?id=712591943593&ns=1&abbucket=0
广式月饼5斤装正宗中秋五仁月饼手工传统老式散装月饼礼盒大,3,山东,400+人付款,食远旗舰店,https://detail.tmall.com/item.htm?id=678789670734&ns=1&abbucket=0

......

蛋月烧月饼老式五仁黑芝麻红枣莲蓉蛋黄月饼中秋正宗传统手工糕点,8,山东,6人付款,沂蒙食品汇,https://item.taobao.com/item.htm?id=726406267679&ns=1&abbucket=0#detail
迷你小月饼伍仁广式老式多种口味袋装凤绿红豆正品中秋节礼盒,3,山东,14人付款,甜招旗舰店,https://detail.tmall.com/item.htm?id=720878205384&ns=1&abbucket=0
好向往芝麻月饼双峰特产传统老式手工五仁月饼中秋月饼糕点早餐饼,7,湖南,2人付款,好向往,https://item.taobao.com/item.htm?id=705999796875&ns=1&abbucket=0#detail
月饼散装,9,北京,18人付款,tb8628352166的小店,https://item.taobao.com/item.htm?id=726508874732&ns=1&abbucket=0#detail
日月坊蔓越莓椰蓉月饼广式小月饼老式传统手工中秋五仁多口味,8,山东,5人付款,日月坊旗舰店,https://detail.tmall.com/item.htm?id=725133049391&ns=1&abbucket=0

拼多多

本来打算爬拼多多的数据,然而拼多多没有网页版。不过我用手机搜了一下拼多多的月饼,最高价28.9元(600g四个月饼),最低价1.36元(26g单个)。除了月饼,我还搜了“月饼礼盒”,最高价58.9元(400g六个月饼),最低价4.72元(408g四个月饼)。当我再一次搜“月饼”的时候,1.36元的月饼找不到了,最低价变成了3.9元。

单以价格而言,拼多多无疑是最低的。