跳到正文
DEV Community· Tabsafely Data·· 3 小時前AI 評分52

用 30 行 Python 建立中國熱門話題監測器(微博、百度、知乎、抖音)

Building a China trending-topics monitor (Weibo, Baidu, Zhihu, Douyin) in 30 lines of Python

AI 導讀

Tabsafely Data 將微博、百度、知乎、抖音、今日頭條及 Bilibili 六個熱榜整合至一個 Apify Actor,並以統一欄位輸出資料。文章示範用 Python 從 Actor 擷取榜單並按指定關鍵詞篩選項目,亦介紹透過排程和 webhook 收集快照,追蹤話題在不同平台的出現次序及持續時間。

正文

Tabsafely Data

What is China talking about right now? If you work in PR, brand monitoring, journalism or you feed LLM pipelines, that question means checking six different hot lists: Weibo hot search (微博热搜), Baidu hot search, Zhihu hot list, Douyin trending, Toutiao and Bilibili — each with its own format, none with an official public API.

I got tired of maintaining six scrapers, so I merged them into one Apify Actor that returns a single unified schema. This post shows how to turn it into a tiny keyword alert.

Disclosure: I built the Actor. Pricing is pay-per-result ($2 / 1,000 items — a full run of ~280 items costs about half a cent).

Unified output

{"platform":"weibo","rank":3,"title":"...","url":"https://s.weibo.com/weibo?q=...",
 "hotValue":1234567,"label":"hot","category":null,"fetchedAt":"2026-10-28T08:16:41Z"}

Every platform maps to the same fields: platform, rank, title, url, hotValue, label, category, fetchedAt.

Fetch everything

import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])
ACTOR = "certified_astronomy_6vi/china-trending-hotlists"

def trending(platforms=("weibo","baidu","zhihu","douyin","toutiao","bilibili"), n=50):
    run = client.actor(ACTOR).call(run_input={
        "platforms": list(platforms), "maxItemsPerPlatform": n})
    return list(client.dataset(run["defaultDatasetId"]).iterate_items())

items = trending(n=10)
for it in items:
    print(f"[{it['platform']:>8}] #{it['rank']:<2} {it['title']}  ({it.get('hotValue')})")

Keyword alert

WATCH = ["特斯拉", "Apple", "小米", "比亚迪"]   # brands you care about

hits = [it for it in trending() if any(k.lower() in it["title"].lower() for k in WATCH)]
for h in hits:
    print(f"ALERT {h['platform']} #{h['rank']}: {h['title']} -> {h['url']}")
    # send to Slack / email / Telegram here

Make it continuous

In the Apify console, create a Schedule (e.g. every hour) for the Actor and add a webhook on ACTOR.RUN.SUCCEEDED pointing to your own endpoint. Each run's dataset becomes one snapshot — append them to a table and you get topic lifecycles: when a topic first appears, which platform picks it up first, how long it stays.

import pandas as pd
df = pd.DataFrame(items)
print(df.groupby("platform")["title"].count())
# Cross-platform topics: same keyword appearing on 3+ lists

English titles?

Titles stay in original Chinese. Pipe them through any translation API or an LLM — batching ~50 titles per prompt is cheap.

Responsible use

Only public trending lists, no login, no personal data, one request per platform per run.

Link: https://apify.com/certified_astronomy_6vi/china-trending-hotlists

Which platform should I add next — Xiaohongshu public trends, 36Kr, or Kuaishou? Let me know.

來源:DEV Community · dev.to