微博热搜 + 中国趋势数据聚合:用 API 一次性抓全平台热点榜单
一、问题:热点分散在各个平台,想聚合太难
想做舆情观察、内容选题、社交媒体研究,热点榜单是绕不开的基础数据。但现实是:微博有微博的热搜,百度、头条、抖音各有各的榜,热点分散在不同平台,你要一个个去看、去抄,很难拼出一张「此刻全网在聊什么」的全景图。
工程上想把这件事做扎实,会碰到几个问题:
- 每个平台的榜单页结构不一样,抓取逻辑要分别写;
- 榜单是实时变化的,你需要带时间戳的快照,而不是一张静态截图;
- 想跨平台对比、想做时间序列,就必须先把它们统一成同一套结构化字段。
二、手动方式的痛点
手动做法就是:开一堆标签页,微博热搜、百度热榜、抖音热点轮着刷,把感兴趣的词抄进表格。问题很明显:
- 快照容易丢:热搜几分钟就变,你抄慢一步就对不上了;
- 无法沉淀时间序列:想分析「某个话题热了多久」,手动根本攒不出连续数据;
- 跨平台没法对齐:各平台字段口径不同,人工对齐既慢又容易错。
我们要的,是输入简单、输出带时间戳的结构化榜单,而且最好能一次覆盖多个平台。
三、方案:两个 Actor 组合使用
这里用两个 Actor 搭配:一个专攻微博热搜、字段最细,另一个负责多平台趋势聚合。
3.1 微博热搜:weibo-hot-search-tracker
输入参数:
limit:返回多少条;category:分类;include_translation:是否附带英文翻译;include_government_topics:是否包含官方/政务类话题;proxyConfiguration:代理配置。
输出字段是明确的,每条包含:rank(排名)、keyword(热搜词)、keyword_english_translation(英文翻译)、category(分类)、heat_score(热度值)、label_chinese(中文标签,如「热」「新」「沸」)、is_new(是否新上榜)、weibo_url(对应链接)、as_of_timestamp(数据时间戳)。
Actor 页面:https://apify.com/nexgendata/weibo-hot-search-tracker?fpr=2ayu9b
import requests
APIFY_TOKEN = "<你的-apify-token>"
def run_actor(slug, payload):
endpoint = (
f"https://api.apify.com/v2/acts/nexgendata~{slug}"
f"/run-sync-get-dataset-items?token={APIFY_TOKEN}"
)
r = requests.post(endpoint, json=payload, timeout=180)
r.raise_for_status()
return r.json()
# 抓微博热搜
weibo_payload = {
"limit": 50,
"include_translation": True,
"include_government_topics": False,
}
weibo = run_actor("weibo-hot-search-tracker", weibo_payload)
print(f"微博热搜共 {len(weibo)} 条")
for item in weibo[:5]:
print(
item.get("rank"),
item.get("keyword"),
"| 热度:", item.get("heat_score"),
"| 标签:", item.get("label_chinese"),
"| 新上榜:", item.get("is_new"),
)
print(" 链接:", item.get("weibo_url"))
print(" 快照时间:", item.get("as_of_timestamp"))
as_of_timestamp 这个字段很关键——它让每次抓取都成为一个可归档的「时间快照」,后面做时间序列分析就靠它。
3.2 多平台趋势:china-trends-tracker
输入参数包括 sources、platforms、urls、source、platform、proxyConfiguration(用于指定要覆盖哪些来源/平台)。
输出字段同样明确,每条包含:source(来源)、rank(排名)、topic(话题)、score(热度分)、label(标签)、url(链接)、scraped_at(抓取时间)。
Actor 页面:https://apify.com/nexgendata/china-trends-tracker?fpr=2ayu9b
# 抓多平台趋势
trends_payload = {
"platforms": ["weibo", "baidu", "douyin", "toutiao"],
}
trends = run_actor("china-trends-tracker", trends_payload)
print(f"多平台趋势共 {len(trends)} 条")
for t in trends[:8]:
print(
f"[{t.get('source')}] #{t.get('rank')}",
t.get("topic"),
"| score:", t.get("score"),
"| label:", t.get("label"),
)
print(" 链接:", t.get("url"), "| 抓取时间:", t.get("scraped_at"))
四、把两份数据聚合成一张表
微博热搜的数据字段更细,多平台趋势的覆盖面更广。把两者对齐到一套统一列,就能拼出全景榜单。用 pandas 最方便:
import pandas as pd
# 微博:统一列名
weibo_df = pd.DataFrame(weibo)
weibo_std = pd.DataFrame({
"source": "weibo",
"rank": weibo_df.get("rank"),
"topic": weibo_df.get("keyword"),
"score": weibo_df.get("heat_score"),
"label": weibo_df.get("label_chinese"),
"url": weibo_df.get("weibo_url"),
"captured_at": weibo_df.get("as_of_timestamp"),
})
# 多平台趋势:统一列名
trends_df = pd.DataFrame(trends)
trends_std = pd.DataFrame({
"source": trends_df.get("source"),
"rank": trends_df.get("rank"),
"topic": trends_df.get("topic"),
"score": trends_df.get("score"),
"label": trends_df.get("label"),
"url": trends_df.get("url"),
"captured_at": trends_df.get("scraped_at"),
})
combined = pd.concat([weibo_std, trends_std], ignore_index=True)
print("聚合后总条数:", len(combined))
print(combined.groupby("source")["topic"].count())
combined.to_csv("trends_combined.csv", index=False, encoding="utf-8-sig")
print("已保存到 trends_combined.csv")
这样你就得到一张「跨平台、带时间戳、字段统一」的热点总表,可以直接拿去做话题重叠分析、跨平台对比,或者喂给可视化面板。
五、定时与自动化:攒出你自己的热点时间线
热点数据的价值高度依赖「连续、密集」。建议每隔一段时间抓一次快照,靠 as_of_timestamp / scraped_at 串成时间序列:
import datetime
def snapshot():
ts = datetime.datetime.now().strftime("%Y%m%d_%H%M")
weibo = run_actor("weibo-hot-search-tracker", {"limit": 50})
trends = run_actor("china-trends-tracker", {"platforms": ["weibo", "baidu", "douyin"]})
# 分别按时间戳落文件,方便日后拼时间线
pd.DataFrame(weibo).to_csv(f"weibo_{ts}.csv", index=False, encoding="utf-8-sig")
pd.DataFrame(trends).to_csv(f"trends_{ts}.csv", index=False, encoding="utf-8-sig")
print(f"快照 {ts} 完成")
配合 Apify 的 Schedule,或者本地 crontab 每小时跑一次:
0 * * * * /usr/bin/python3 /home/you/jobs/snapshot_trends.py >> /home/you/logs/trends.log 2>&1
积累几天,你就有了一份属于自己的热点时间线,可以分析「某话题从上榜到掉榜持续了多久」「哪个平台先发酵、哪个平台后跟进」这类真正有意思的问题。
六、小结
热点聚合的难点,从来不是分析,而是稳定、连续地拿到带时间戳的结构化榜单。weibo-hot-search-tracker 给了你字段最细的微博热搜(含 rank、heat_score、label_chinese、is_new、as_of_timestamp 等),china-trends-tracker 帮你覆盖多平台(source、topic、score、scraped_at)。两者组合,几十行 Python 就能搭起一套跨平台热点聚合与时间线归档的管线。
更多面向中文与 APAC 场景的数据采集 Actor,欢迎到 https://thenextgennexus.com 逛逛。你会怎么用这份热点数据?评论区聊聊。