百度貼吧回覆 API
依 2026-11-21 規格整理
快速解答
POST /tieba/pushs/task 帶貼文網址(tieba.baidu.com 或 m.tieba.baidu.com 的 /p/{貼文 ID}),會蒐集該貼文從二樓起的所有樓層,crawl_second_layer(預設 true)時一併蒐集每層的樓中樓回覆。max_pages 限制樓層頁數(0 到 500;0 或省略為 100,每頁 30 層)。以 GET /tieba/pushs/task/{task_id} 輪詢,DONE 時回傳 task、total_count 與 data,每頁最多 1000 筆。每筆資料有 post_id(貼文的文件 ID)、push_type(樓層為 comment,樓中樓為 reply)、回覆者、內容、時間、情緒標籤,樓層另有 IP 所在地。資料以網路爬蟲蒐集百度貼吧公開發布的內容。
常見用途
- 完整讀取一篇熱門貼文關於某個產品或事件的討論。
- 觀察回覆語氣從前面樓層到後面樓層的變化。
- 搭配貼文搜尋,追蹤回覆最多的貼文。
端點一覽
Base URL 為 https://api.infominer.io/api/v2,每個請求以 auth-header 標頭帶 API 金鑰。
| 方法 | 路徑 | 說明 |
|---|---|---|
| POST | /tieba/pushs/task |
以貼文網址建立回覆任務:二樓以後的樓層,可一併蒐集樓中樓回覆。 |
| GET | /tieba/pushs/task/{task_id} |
輪詢回覆任務;DONE 時回傳樓層與回覆,每頁最多 1000 筆。 |
請求參數
POST /tieba/pushs/task
| 參數 | 位置 | 型別 | 必填 | 預設值/可用值 | 說明 |
|---|---|---|---|---|---|
post_url |
body | string | 是 | 貼吧貼文網址 https://tieba.baidu.com/p/{貼文 ID}(也接受 m.tieba.baidu.com)。 | |
crawl_second_layer |
body | boolean | 否 | true |
一併蒐集每層的樓中樓回覆。 |
max_pages |
body | integer | 否 | 100(最多 500) |
樓層最多爬取的頁數,每頁 30 層;0 或省略時用預設值。 |
rerun |
body | boolean | 否 | 為了與其他平台一致而接受此參數;每次 POST 都會建立新任務。 |
GET /tieba/pushs/task/{task_id}
| 參數 | 位置 | 型別 | 必填 | 預設值/可用值 | 說明 |
|---|---|---|---|---|---|
task_id |
path | string | 是 | 建立任務時回傳的任務 ID。 | |
page |
query | integer | 否 | 1 |
頁碼,從 1 開始。 |
pageSize |
query | integer | 否 | 1000 |
每頁樓層與回覆數,最多 1000。 |
回應欄位
| 資料 | 欄位 | 端點 |
|---|---|---|
| 樓層與樓中樓回覆(data) | id, post_id, author_id, author, push_type, region, content, tm, tm_crawler, sentiment | GET /tieba/pushs/task/{task_id} |
| 任務(task) | task: id, post_url, status, crawl_second_layer, created_at, total, completed, pages_crawled, reported_total, partial, timed_out, failed_pages, failed_batches, tid, title, forum | GET /tieba/pushs/task/{task_id} |
程式碼範例
curl:建立任務
curl -X POST https://api.infominer.io/api/v2/tieba/pushs/task \
-H "auth-header: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"post_url": "https://tieba.baidu.com/p/10000000001", "crawl_second_layer": true, "max_pages": 2}'
curl:以任務 ID 輪詢
curl "https://api.infominer.io/api/v2/tieba/pushs/task/$TASK_ID?page=1&pageSize=1000" \
-H "auth-header: YOUR_API_KEY"
Python(requests):建立、輪詢、讀取
import time
import requests
BASE_URL = "https://api.infominer.io/api/v2"
HEADERS = {"auth-header": "YOUR_API_KEY"}
# 1. Create the task
resp = requests.post(
f"{BASE_URL}/tieba/pushs/task",
headers=HEADERS,
json={
"post_url": "https://tieba.baidu.com/p/10000000001",
"crawl_second_layer": True,
"max_pages": 2,
},
timeout=30,
)
resp.raise_for_status()
task = resp.json()
# 2. Poll until the task leaves INIT / RUNNING
for _ in range(120):
resp = requests.get(
f"{BASE_URL}/tieba/pushs/task/{task['id']}",
headers=HEADERS,
params={
"page": 1,
"pageSize": 1000,
},
timeout=30,
)
resp.raise_for_status()
result = resp.json()
status = result.get("status") or result.get("task", {}).get("status")
if status not in ("INIT", "RUNNING"):
break
time.sleep(15)
else:
raise SystemExit("task still running; poll it again later")
task = result.get("task", result)
if status != "DONE" or task.get("partial") or task.get("timed_out"):
raise SystemExit(f"task ended with status {status}; no complete result")
# 3. Read the records (use page / pageSize to fetch further pages)
for row in result.get("data", []):
print(row.get("push_type"), row.get("author"), (row.get("content") or "")[:60])
示意回應樣本
以下為人工撰寫的示意資料:帳號為 sample_user_n,ID 明顯為假值。欄位依 2026-11-21 規格,範例只列出部分欄位。
任務 DONE 後的輪詢回應(示意資料)
{
"task": {
"id": "00000000-0000-4000-8000-000000000001",
"post_url": "https://tieba.baidu.com/p/10000000001",
"status": "DONE",
"crawl_second_layer": true,
"created_at": 1780880400,
"total": 3,
"completed": 3,
"pages_crawled": 1,
"reported_total": 3,
"timed_out": false,
"partial": false,
"failed_pages": 0,
"failed_batches": 0,
"tid": "10000000001",
"title": "入门公路车预算五千,大家帮忙看看这两款",
"forum": "骑行"
},
"total_count": 3,
"data": [
{
"id": "00000000-0000-4000-8000-000000000003",
"post_id": "00000000-0000-4000-8000-000000000001",
"author_id": "0000000003",
"author": "sample_user_3",
"tm": 1780745400,
"tm_crawler": 1780880403,
"push_type": "comment",
"region": "广东",
"content": "通勤为主的话选第二款,变速更好调",
"sentiment": "Positive"
},
{
"id": "00000000-0000-4000-8000-000000000004",
"post_id": "00000000-0000-4000-8000-000000000001",
"author_id": "0000000004",
"author": "sample_user_4",
"tm": 1780743600,
"tm_crawler": 1780880406,
"push_type": "reply",
"region": "",
"content": "同意,我骑了一年没出过问题",
"sentiment": "Positive"
},
{
"id": "00000000-0000-4000-8000-000000000005",
"post_id": "00000000-0000-4000-8000-000000000001",
"author_id": "0000000005",
"author": "sample_user_5",
"tm": 1780741800,
"tm_crawler": 1780880409,
"push_type": "comment",
"region": "湖北",
"content": "先去店里试骑再决定吧",
"sentiment": "Neutral"
}
],
"page": 1,
"pageSize": 1000
}
限制與注意事項
- 一樓(貼文本身)不在 data 裡,它的全文是貼文搜尋回傳的 content。
- 每層樓中樓回覆最多 600 則(每頁 30 則、20 頁)。
- 樓中樓回覆的 region(IP 所在地)一律為空值,樓層會帶。
- 數千層的貼文可能需要數分鐘以上,大型貼文請設定 max_pages。
- 只有 DONE 的輪詢回應帶資料,PARTIAL、TIMED_OUT 與 FAILED 只回傳任務物件。status 為 DONE 且 partial、timed_out 都是 false,才算完全成功。
- data 包含這篇貼文所有已蒐集的回覆(含先前任務蒐集的),所以 total_count 與 task.completed 不一定相同。數值是蒐集當下的值。
更多 百度貼吧 API 頁面
- 貼文關鍵字搜尋
- 樓層與回覆
申請試用
填寫下方申請表單時,請註明百度貼吧,並說明要追的關鍵字、吧名或貼文、是否需要樓層與樓中樓回覆,以及預估資料量。我們會確認範圍,並回覆試用與 API 金鑰的安排。
填寫表單申請試用,專人確認範圍後回覆試用與介接安排。
填寫申請表單常見問題
- 為什麼沒有一樓?
- 一樓就是貼文本身,它的全文在搜尋任務回傳貼文的 content;回覆任務回傳的是二樓以後的樓層與樓中樓回覆。
- 每層可以蒐集幾則樓中樓回覆?
- 每層最多 600 則(每頁 30 則、20 頁)。
- reported_total 代表什麼?
- 貼吧顯示的這篇貼文回覆數。與 task.completed 比對,可以知道蒐集了多少。
- 資料是怎麼蒐集的?這是百度貼吧官方的 API 嗎?
- 資料以網路爬蟲蒐集百度貼吧公開發布的內容。LargitData 與百度貼吧沒有隸屬或合作關係,這也不是百度貼吧自身提供的 API。是否適用於您的用途,依用途與法域由買方法務評估,我們可提供來源與蒐集方式說明。