# 小紅書筆記 ID 是什麼，在連結裡哪一段？

> 小紅書筆記 ID 是 24 位十六進位制字元，在筆記連結 /explore/ 或 /discovery/item/ 後面。怎麼認出它、常和什麼搞混，以及介面怎麼用它。

網頁版：https://okdata.online/zh-hant/answers/xiaohongshu-note-id/

**簡短回答：**就是筆記連結裡 /explore/ 或 /discovery/item/ 後面、?xsec_token 前面那串 24 位十六進位制字元。okdata 的小紅書筆記詳情可以直接傳這個 ID 或整條連結，每次 $0.035，返回的筆記 id 就是它；筆記搜尋每次 $0.035，一頁約 20 篇，都帶 ID。

每篇小紅書筆記都有一個正好 24 位的 ID，只由數字和 a 到 f 的字母組成，比如 `66f3c1a8000000002c03e5b7`。它是筆記連結裡唯一不變的部分：問號後面的 `xsec_token` 每次訪問都重新發放、會過期，xhslink.com 短鏈裡的分享碼要跳轉後才有意義，而這 24 位只要筆記還在就一直不變。所以表格和資料庫裡應該存它；大家貼來的連結五花八門時，要提取的也是它。

## 在各種連結裡的位置

| 連結 | 筆記 ID 是 |
|---|---|
| `xiaohongshu.com/explore/66f3c1a8000000002c03e5b7?xsec_token=AB…` | `/explore/` 後面那段 |
| `xiaohongshu.com/discovery/item/66f3c1a8000000002c03e5b7` | `/discovery/item/` 後面那段 |
| `xiaohongshu.com/user/profile/5f2b7c1e0000000001006a3d/66f3c1a8000000002c03e5b7` | 最後一段；前一段是作者的使用者 ID |
| `xhslink.com/a/Hk3pQx2Lm9` | 看不到，短鏈要先跳轉 |

前三種可以用這個正則：`/(?:explore|discovery/item|user/profile/[0-9a-f]{24})/([0-9a-f]{24})`。

## 容易和什麼搞混

- **使用者 ID** 也是 24 位十六進位制。`/user/profile/` 連結裡第一段 24 位是帳號，不是筆記。
- **評論 ID** 長得也一樣。表格裡每一列都標清楚。
- **xsec_token** 是一長串令牌，不屬於 ID，見[要不要 xsec_token](/zh/answers/xiaohongshu-xsec-token/)。

還有一個特性：前 8 位按十六進位制讀，是一個 Unix 時間戳。我們核對過的筆記裡，它都和釋出時間對得上（`66f3c1a8` 是 2024 年 9 月下旬）。小紅書沒有公開說明這一點，所以報表裡用 `published_at`，這個技巧只用來快速排個序。

## 介面怎麼收、怎麼返回

[小紅書筆記詳情](/zh/apis/xiaohongshu/notes/get/)可以傳 `id=66f3c1a8000000002c03e5b7`，也可以用 `url=` 傳 `/explore/`、`/discovery/item/` 或 xhslink.com 連結。`/user/profile/<使用者>/<筆記>` 這種連結，把最後一段作為 `id` 傳。不需要令牌。返回 `id`、規範連結 `url`（`/explore/<id>`）、`type`（`image` 或 `video`）、標題、正文、圖片、點贊、收藏、評論、分享和話題；加 `view=full` 時，`ext.xsec_token` 裡是小紅書附帶的令牌（有的話）。[筆記搜尋](/zh/apis/xiaohongshu/notes/search/)的每條結果也帶同樣的 `id`。

| 任務 | 呼叫次數 | 費用 |
|---|---|---|
| 一個 ID 或連結換完整筆記 | 1 | $0.035 |
| 上個月投放的 250 個筆記 ID | 250 | $8.75 |
| 一頁搜尋結果，帶筆記 ID 和資料 | 1 | $0.035 |

## 示例

```python
import os, re, requests

links = ["https://www.xiaohongshu.com/discovery/item/66f3c1a8000000002c03e5b7?source=webshare"]
pattern = re.compile(r"/(?:explore|discovery/item|user/profile/[0-9a-f]{24})/([0-9a-f]{24})")
for link in links:
    note_id = pattern.search(link).group(1)
    r = requests.get("https://api.okdata.online/v1/xiaohongshu/notes/get",
                     headers={"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"},
                     params={"id": note_id, "fields": "id,type,title,published_at,metrics.likes"},
                     timeout=60)
    print(r.json()["data"]["item"])
```

## 限制

- 已刪除或私密的筆記返回 `not_found`，這次呼叫照常計費。
- `metrics.views` 為 null，小紅書不公開瀏覽量。
- 一次呼叫一篇筆記，沒有批次詳情介面。整段分享文案怎麼處理，見[小紅書分享連結轉筆記資料](/zh/answers/xiaohongshu-note-from-share-link/)。

## 用到的介面

- [小紅書筆記詳情](https://okdata.online/zh/apis/xiaohongshu/notes/get/) `xiaohongshu.notes.get`：$0.035/次
- [小紅書筆記搜尋](https://okdata.online/zh/apis/xiaohongshu/notes/search/) `xiaohongshu.notes.search`：$0.035/次 · 每頁約 20 篇筆記

## 更多小紅書內容

- [小紅書 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/)
- [海外品牌怎麼監控小紅書上的品牌討論？](https://okdata.online/zh/answers/monitor-rednote-brand-mentions-outside-china/)
- [人在海外，怎麼讓 AI 讀到國內版小紅書的資料？](https://okdata.online/zh/answers/xiaohongshu-data-for-agents-outside-china/)
- [怎麼搭一個小紅書爆款筆記庫，用來找選題、拆爆文？](https://okdata.online/zh/answers/xiaohongshu-viral-notes-library/)
- [千問裡怎麼拿到抖音、小紅書、公眾號的資料？](https://okdata.online/zh/answers/qwen-douyin-xiaohongshu-data/)
- [騰訊元寶能讀抖音、小紅書的資料嗎？](https://okdata.online/zh/answers/yuanbao-douyin-xiaohongshu-data/)
- [小紅書返回 300011 帳號異常，怎麼繼續採集筆記？](https://okdata.online/zh/answers/xiaohongshu-300011-account-abnormal/)
- [自己爬還是按次呼叫資料介面：成本、維護和風險](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/)

## 資料來源

- [XHS-Downloader README: supported link formats (/explore/, /discovery/item/, /user/profile/…/…, xhslink.com)](https://github.com/JoeanAmier/XHS-Downloader) (讀取於 2026-11-12)
- [Knowing the note ID, how to get xsec_token? (XHS-Downloader issue #397)](https://github.com/JoeanAmier/XHS-Downloader/issues/397) (讀取於 2026-11-12)

這個問題出現過的地方（讀取於 2026-11-12）：

- https://github.com/JoeanAmier/XHS-Downloader/issues/397
- https://github.com/ReaJason/xhs/issues/107

更新於 2026-11-12
