# 怎麼按關鍵詞批次匯出小紅書評論

> 按關鍵詞搜小紅書筆記，留下討論最多的幾篇，再把它們的評論一頁頁拉進一張 CSV：用到的兩個介面、關鍵引數、Python 程式碼和花費。

網頁版：https://okdata.online/zh-hant/guides/xiaohongshu-note-comments/

兩個介面：先用小紅書筆記搜尋，再對留下的每篇筆記調小紅書筆記評論。下面的示例一共 7 次呼叫，花費 $0.245；請求到了平台的呼叫，返回為空、查不到或出錯也照常計費。

更新於 2026-11-12

要做的事：新品要上市，或者要和某個競品正面競爭，想知道小紅書使用者對這個品類到底怎麼說。筆記代表博主想讓你看到的東西，筆記下面的評論才是讀者真正在問、在懷疑、在比較的東西。所以先搜關鍵詞，留下討論最多的那幾篇，再一頁一頁讀評論。最後得到一張 CSV：筆記標題、評論內容、評論者、點贊數、回覆數、時間，以及小紅書在評論旁顯示的 IP 屬地。

整個過程不需要小紅書帳號，不用 Cookie，也不用處理 xsec_token。每次呼叫就是帶著 key 發一個 HTTPS 請求。

## 分步操作

### 第一步：找到值得讀的筆記

呼叫[小紅書筆記搜尋](https://okdata.online/zh/apis/xiaohongshu/notes/search/)，`query` 按使用者在 App 裡的搜法寫：`防曬霜`、`防曬霜 油皮`、`敏感肌 防曬`。這裡有兩個引數要關注：

- `sort`：`general`（預設，小紅書的綜合排序）、`latest`（最新）或 `popular`（最熱）。挖評論時用 `popular`，互動最多的筆記通常就是討論最熱鬧的。
- `type`：`all`（預設）、`video`（影片筆記）或 `image`（圖文筆記）。除非只關心一種形式，否則保持 `all`。

一次呼叫返回約 20 篇筆記，每次 $0.035。每篇有 `id`（24 位十六進位制）、`title`、正文開頭、`author`、`published_at`，以及包含點贊、收藏（favorites）和評論數的 `metrics`。按 `metrics.comments` 排序，就知道該開啟哪幾篇。

```bash
curl -G "https://api.okdata.online/v1/xiaohongshu/notes/search" \
  -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'query=防曬霜' \
  --data-urlencode 'sort=popular' \
  --data-urlencode 'fields=id,title,metrics.comments,metrics.likes,published_at'
```

`fields` 只保留你點名的欄位，返回更短，價格不變。

### 第二步：一頁頁讀評論

把筆記 `id` 傳給[小紅書筆記評論](https://okdata.online/zh/apis/xiaohongshu/notes/comments/list/)。一次呼叫返回約 10 條一級評論，每次 $0.035。每條有 `text`、`author`（暱稱和 ID）、`likes`、`replies`（下面有幾條回覆）、`published_at` 和 `ip_location`。這些都是一級評論，所以 `parent_id` 為 null。要下一頁，就把 `page.next_cursor` 原樣作為 `cursor` 傳回去；`page.has_more` 為 `false` 時說明到底了。

```bash
curl -G "https://api.okdata.online/v1/xiaohongshu/notes/comments/list" \
  -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'id=672a4f1d000000001b03c58e'
```

小紅書的評論一頁條數不多，所以預算要按頁算，不要按筆記算：1000 條評論大約要 100 次呼叫。

### 第三步：用 Python 串起來

下面的指令碼搜尋一次，按評論數挑出前 3 篇筆記，每篇最多讀 `MAX_PAGES` 頁，最後寫成一張 CSV。

```python
import csv
import os
import requests

API = "https://api.okdata.online"
HEADERS = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}
NOTES = 3      # 開啟幾篇筆記
MAX_PAGES = 2  # 每篇讀幾頁評論；每頁一次呼叫


def get(path, **params):
    body = requests.get(API + path, headers=HEADERS, params=params, timeout=60).json()
    if body["code"] != "ok":
        raise RuntimeError(f"{body['code']}: {body['message']} (charged: {body['charged']})")
    return body


notes = get("/v1/xiaohongshu/notes/search", query="防曬霜", sort="popular")["data"]["items"]
notes = sorted(notes, key=lambda n: n["metrics"]["comments"] or 0, reverse=True)[:NOTES]

with open("xhs_comments.csv", "w", newline="", encoding="utf-8-sig") as f:
    out = csv.writer(f)
    out.writerow(["note_id", "note_title", "comment", "user", "likes", "replies", "ip_location", "published_at"])
    for n in notes:
        cursor = None
        for _ in range(MAX_PAGES):
            params = {"id": n["id"], **({"cursor": cursor} if cursor else {})}
            body = get("/v1/xiaohongshu/notes/comments/list", **params)
            for c in body["data"]["items"]:
                out.writerow([n["id"], n["title"], c["text"], c["author"]["name"], c["likes"],
                              c["replies"], c["ip_location"], c["published_at"]])
            if not body["page"]["has_more"]:
                break
            cursor = body["page"]["next_cursor"]
```

想覆蓋更多筆記、讀得更深，就調大 `NOTES` 和 `MAX_PAGES`。10 篇筆記各讀 5 頁是 50 次評論呼叫，在搜尋之外再花 $1.75。按每 1000 條評論算，大約 $3.50。

## 注意事項

- **條數和筆記上的數字對不上。** 筆記顯示的評論數包含了樓中樓回覆。這個介面列的是一級評論，每條的回覆數在 `replies` 裡，但沒有回覆正文，所以拿到的行數會比 `metrics.comments` 少。
- **排序。** 評論按小紅書預設順序返回，沒有排序引數，也沒有按最新排序的選項。
- **IP 屬地。** `ip_location` 是小紅書顯示在評論旁邊的省份或國家，沒顯示時為 null。
- **不用管 token。** 只傳筆記 ID 就行。為什麼這一點在小紅書上很重要，見 [xsec_token 那篇問答](https://okdata.online/zh/answers/xiaohongshu-xsec-token/)。
- **刪掉的筆記也計費。** 已刪除或設為私密的筆記返回 `not_found`，照常計費，跳過即可。
- **重發同一個請求不重複扣費。** 每次呼叫帶一個 `Idempotency-Key` 請求頭。24 小時內同樣的請求配同樣的 key，會直接拿回上次的結果，`meta.replayed` 為 `true`，不再扣費。平台出錯後的重試算一次新呼叫，照常計費。

如果是要匯出某一篇筆記下的全部評論，看[怎麼匯出小紅書筆記的全部評論](https://okdata.online/zh/answers/xiaohongshu-export-note-comments/)。想把評論整理成使用者痛點和問題清單，看[怎麼用大模型從抖音和小紅書評論裡找痛點](https://okdata.online/zh/answers/llm-comment-pain-points-douyin-xiaohongshu/)。

## 示例花費

按最熱搜一頁“防曬霜”筆記，再取評論最多的 3 篇，每篇讀兩頁評論

| 介面 | 呼叫次數 | 單價 | 小計 |
|---|---|---|---|
| [小紅書筆記搜尋](https://okdata.online/zh/apis/xiaohongshu/notes/search/) | 1 | $0.035 | $0.035 |
| [小紅書筆記評論](https://okdata.online/zh/apis/xiaohongshu/notes/comments/list/) | 6 | $0.035 | $0.21 |
| 合計 | 7 |  | $0.245 |

按本頁生成時的價格計算。請求到了平台的呼叫，返回為空或出錯也照常計費。

## 在你的 AI 裡用（MCP）

先接好 MCP 服務，然後直接說你要什麼。智慧體會自己找到這些介面、看清價格，再用你的餘額呼叫。

可以這樣說：在小紅書按最熱搜“防曬霜”，挑評論最多的 3 篇筆記，每篇讀兩頁評論，整理成一張表：筆記標題、評論內容、點贊、回覆數、IP 屬地、時間。

```json
{
  "endpoint": "xiaohongshu.notes.search",
  "params": {
    "query": "防曬霜 推薦"
  },
  "idempotency_key": "<新的 UUID>"
}
```

MCP：`https://api.okdata.online/mcp`

## 本指南用到的介面

- [小紅書筆記搜尋](https://okdata.online/zh/apis/xiaohongshu/notes/search/) `xiaohongshu.notes.search`：$0.035/次 · 每頁約 20 篇筆記
- [小紅書筆記評論](https://okdata.online/zh/apis/xiaohongshu/notes/comments/list/) `xiaohongshu.notes.comments.list`：$0.035/次 · 每頁約 10 條評論

## 更多小紅書內容

- [小紅書 API](https://okdata.online/zh/apis/xiaohongshu/)
- [小紅書 API Python 教程：筆記、博主和評論（2026）](https://okdata.online/zh/guides/xiaohongshu-api-python/)
- [怎麼按關鍵詞批次匯出小紅書評論](https://okdata.online/zh/guides/xiaohongshu-note-comments/)
- [怎麼在小紅書蒲公英按報價和閱讀量篩達人](https://okdata.online/zh/guides/xiaohongshu-pgy-creator-rates/)
- [怎麼搜尋小紅書筆記並匯出成 CSV 表格](https://okdata.online/zh/guides/xiaohongshu-search-export-notes/)
- [OpenClaw（龍蝦）裡怎麼裝小紅書、抖音、公眾號的資料 Skill？](https://okdata.online/zh/answers/openclaw-xiaohongshu-douyin-skill/)
- [千問裡怎麼拿到抖音、小紅書、公眾號的資料？](https://okdata.online/zh/answers/qwen-douyin-xiaohongshu-data/)
- [怎麼讓豆包讀到抖音、小紅書的資料？](https://okdata.online/zh/answers/doubao-douyin-xiaohongshu-data/)
- [騰訊元寶能讀抖音、小紅書的資料嗎？](https://okdata.online/zh/answers/yuanbao-douyin-xiaohongshu-data/)
- [怎麼在 Cursor 或 Cline 裡接入小紅書資料的 MCP？](https://okdata.online/zh/answers/cursor-cline-xiaohongshu-mcp/)
- [怎麼用大模型從抖音、小紅書評論裡提煉使用者痛點？](https://okdata.online/zh/answers/llm-comment-pain-points-douyin-xiaohongshu/)
- [自己爬還是按次呼叫資料介面：成本、維護和風險](https://okdata.online/zh/compare/scraping-vs-data-api/)
- [怎麼選社交媒體資料 API（2026）](https://okdata.online/zh/compare/social-media-data-apis/)
- [社媒資料 MCP 伺服器：自己部署還是用託管的](https://okdata.online/zh/compare/social-media-data-mcp-servers/)
