百度貼吧貼文搜尋 API
依 2026-11-21 規格整理
快速解答
POST /tieba/search/task 以關鍵字與發文日期區間(YYYY-MM-DD,UTC+8,含當日;預設最近 7 天)搜尋貼吧貼文,由新到舊,並為區間內每篇貼文蒐集一樓全文、回覆數與按讚數、吧名,以及發文者的 IP 所在地。max_pages 為 0 到 31(0 或省略為 31),每頁 20 篇,一次查詢約 620 篇;整頁都早於 start_date 時任務會提早結束。以 GET /tieba/search/task/{task_id} 輪詢,DONE 時回應帶有 task、total_count 與 data,每頁最多 100 筆。資料以網路爬蟲蒐集百度貼吧公開發布的內容。
常見用途
- 追蹤貼吧各吧對某個產品、品牌或地方議題的討論。
- 為研究蒐集某主題附日期的貼文,並依回覆數找出最熱絡的討論。
- 把貼文網址交給貼吧回覆 API,讀取樓層與樓中樓回覆。
端點一覽
Base URL 為 https://api.infominer.io/api/v2,每個請求以 auth-header 標頭帶 API 金鑰。
| 方法 | 路徑 | 說明 |
|---|---|---|
| POST | /tieba/search/task |
建立貼文關鍵字搜尋任務,可指定日期區間與最多爬取頁數。 |
| GET | /tieba/search/task/{task_id} |
輪詢搜尋任務;DONE 時回傳貼文與 total_count,每頁最多 100 筆。 |
請求參數
POST /tieba/search/task
| 參數 | 位置 | 型別 | 必填 | 預設值/可用值 | 說明 |
|---|---|---|---|---|---|
keyword |
body | string | 是 | 搜尋關鍵字,1 到 100 字。 | |
end_date |
body | string | 否 | 迄日,含當日(YYYY-MM-DD,UTC+8)。預設為今天。 | |
max_pages |
body | integer | 否 | 31(最多 31) |
最多爬取的結果頁數;0 或省略時用預設值。每頁 20 篇。 |
rerun |
body | boolean | 否 | 為了與其他平台一致而接受此參數;每次 POST 都會建立新任務。 | |
start_date |
body | string | 否 | 起日,含當日(YYYY-MM-DD,UTC+8)。預設為 7 天前。 |
GET /tieba/search/task/{task_id}
| 參數 | 位置 | 型別 | 必填 | 預設值/可用值 | 說明 |
|---|---|---|---|---|---|
task_id |
path | string | 是 | 建立任務時回傳的任務 ID。 | |
page |
query | integer | 否 | 1 |
頁碼,從 1 開始。 |
pageSize |
query | integer | 否 | 100 |
每頁貼文數,最多 100。 |
回應欄位
| 資料 | 欄位 | 端點 |
|---|---|---|
| 貼文(data) | id, url, title, content, tm, datetime, tm_crawler, tm_update, author, author_id, type, ctype, source, sentiment, region, comment_count, like_count, share_count, metadata_img, metadata_videos | GET /tieba/search/task/{task_id} |
| 搜尋任務(task) | task: id, keyword, status, start_date, end_date, max_pages, created_at, total, completed, pages_crawled, partial, timed_out, failed_pages, failed_articles, failed_ranges, deleted, depth_capped | GET /tieba/search/task/{task_id} |
程式碼範例
curl:建立任務
curl -X POST https://api.infominer.io/api/v2/tieba/search/task \
-H "auth-header: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"keyword": "公路车", "start_date": "2026-06-01", "end_date": "2026-06-07", "max_pages": 3}'
curl:以任務 ID 輪詢
curl "https://api.infominer.io/api/v2/tieba/search/task/$TASK_ID?page=1&pageSize=100" \
-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/search/task",
headers=HEADERS,
json={
"keyword": "公路车",
"start_date": "2026-06-01",
"end_date": "2026-06-07",
"max_pages": 3,
},
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/search/task/{task['id']}",
headers=HEADERS,
params={
"page": 1,
"pageSize": 100,
},
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("url"), (row.get("title") or "")[:60])
示意回應樣本
以下為人工撰寫的示意資料:帳號為 sample_user_n,ID 明顯為假值。欄位依 2026-11-21 規格,範例只列出部分欄位。
任務 DONE 後的輪詢回應(示意資料)
{
"task": {
"id": "00000000-0000-4000-8000-000000000001",
"keyword": "公路车",
"status": "DONE",
"start_date": "2026-06-01",
"end_date": "2026-06-07",
"max_pages": 3,
"created_at": 1780880400,
"total": 2,
"completed": 2,
"pages_crawled": 1,
"deleted": 0,
"depth_capped": false,
"timed_out": false,
"partial": false,
"failed_pages": 0,
"failed_articles": 0,
"failed_ranges": 0
},
"total_count": 2,
"data": [
{
"id": "00000000-0000-4000-8000-000000000001",
"url": "https://tieba.baidu.com/p/10000000001",
"title": "入门公路车预算五千,大家帮忙看看这两款",
"content": "平时通勤加周末骑行,身高 175,主要在两款之间犹豫,想听听吧友的意见",
"tm": 1780666200,
"datetime": "2026-06-05 21:30:00",
"tm_crawler": 1780880404,
"tm_update": 1780880404,
"author": "sample_user_1",
"author_id": "0000000001",
"type": [
"骑行"
],
"ctype": [
"骑行"
],
"source": "tieba",
"sentiment": "Neutral",
"region": "江苏",
"comment_count": 3,
"like_count": 5,
"share_count": 0,
"metadata_img": [],
"metadata_videos": []
},
{
"id": "00000000-0000-4000-8000-000000000002",
"url": "https://tieba.baidu.com/p/10000000002",
"title": "公路车周末环湖骑行记录,风景很好",
"content": "公路车周末环湖骑行记录,风景很好",
"tm": 1780452000,
"datetime": "2026-06-03 10:00:00",
"tm_crawler": 1780880408,
"tm_update": 1780880408,
"author": "sample_user_2",
"author_id": "0000000002",
"type": [
"骑行"
],
"ctype": [
"骑行"
],
"source": "tieba",
"sentiment": "Positive",
"region": "浙江",
"comment_count": 8,
"like_count": 12,
"share_count": 1,
"metadata_img": [
"https://tiebapic.baidu.com/forum/pic/item/sample_1.jpg"
],
"metadata_videos": []
}
],
"page": 1,
"pageSize": 100
}
限制與注意事項
- 一次查詢最多約 31 頁,約 620 篇。沒有涵蓋到日期區間前段時 depth_capped 為 true,請把區間拆小。
- 搜尋只比對貼文標題與一樓內容;關鍵字只出現在回覆裡的貼文不會被列出,列表上出現、但內文沒有完整包含關鍵字的貼文,也可能不在 data 裡。
- deleted 是列表上出現、但蒐集時已被刪除或隱藏的貼文數,不算失敗。
- 只有 DONE 的輪詢回應帶資料,PARTIAL、TIMED_OUT 與 FAILED 只回傳任務物件。status 為 DONE 且 partial、timed_out 都是 false,才算完全成功。
- data 是該區間內所有已蒐集資料的比對結果,包含先前任務蒐集的,所以 total_count 可能大於 task.completed;這個任務實際蒐集的筆數是 task.completed。
- 數值是蒐集當下的值,不會自動更新。可回溯的期間依專案範圍確認。
蒐集方式:以網路爬蟲蒐集各平台公開發布的內容。是否適用於您的用途,依用途與法域由買方法務評估,我們可提供來源與蒐集方式說明。
更多 百度貼吧 API 頁面
- 貼文關鍵字搜尋
- 樓層與回覆
申請試用
填寫下方申請表單時,請註明百度貼吧,並說明要追的關鍵字、吧名或貼文、是否需要樓層與樓中樓回覆,以及預估資料量。我們會確認範圍,並回覆試用與 API 金鑰的安排。
填寫表單申請試用,專人確認範圍後回覆試用與介接安排。
填寫申請表單常見問題
- depth_capped 是什麼意思?
- 貼吧的搜尋頁在涵蓋到日期區間起點前就用完了,區間前段沒有被蒐集到。請把區間拆小再建立任務。
- 怎麼知道貼文來自哪個吧?
- type 與 ctype 是吧名;貼文網址為 https://tieba.baidu.com/p/{貼文 ID}。
- 貼吧搜尋會比對回覆的內容嗎?
- 不會,只比對貼文標題與一樓內容。
- 資料是怎麼蒐集的?這是百度貼吧官方的 API 嗎?
- 資料以網路爬蟲蒐集百度貼吧公開發布的內容。LargitData 與百度貼吧沒有隸屬或合作關係,這也不是百度貼吧自身提供的 API。是否適用於您的用途,依用途與法域由買方法務評估,我們可提供來源與蒐集方式說明。