小红书有 API 吗?用 Python 拉取笔记和评论(2026)

小红书开放平台只管电商(订单、商品、物流),没有笔记、评论和搜索接口;要用程序读笔记和评论,用第三方数据接口。下面用 DataXAPI 的 Python SDK 演示,免费试用,最多 333 次。 用 2 个接口:小红书笔记搜索 → 小红书笔记评论。下面的示例一共 11 次调用,合计 $0.22;失败的调用不收费。

更新于 2026-11-06在 ChatGPT 里打开在 Claude 里打开

按关键词搜出一页笔记,取前 10 篇的评论,写进一张 CSV:笔记标题、点赞数、评论正文、评论点赞数、时间。先 pip install dataxapi,Key 放在环境变量 DATAXAPI_API_KEY。

第 1 步:小红书笔记搜索

按搜索词取一页笔记,sort 可以选最新或最热。每条的 id 是笔记编号,metrics.likes 是点赞数。

curl -G "https://api.dataxapi.com/v1/xiaohongshu/notes/search" \
  --data-urlencode "query=咖啡" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
# pip install dataxapi
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.xiaohongshu.notes.search(query="咖啡")
print(result["data"]["items"])
// npm i @dataxapi/sdk
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.xiaohongshu.notes.search({ query: "咖啡" });
console.log(result.data.items);
dataxapi call xiaohongshu.notes.search 'query=咖啡'
录制的返回
{
  "code": "ok",
  "request_id": "d2403177-e4f6-4d04-99eb-afce599b4c31",
  "data": {
    "items": [
      {
        "id": "67d5e2be00000000d803d22d",
        "url": "https://www.xiaohongshu.com/explore/67d5e2be00000000d803d22d",
        "type": "image",
        "title": "实测一个月咖啡,结论有点意外",
        "text": "把咖啡从头到尾讲清楚,看完少走弯路",
        "published_at": "2026-05-17T05:25:25.000Z",
        "author": {
          "id": "6130783200000000883b2a1e",
          "username": "coffee_lab_sh",
          "name": "山野咖啡馆",
          "avatar_url": "https://sns-avatar-qc.xhscdn.com/avatar/610f17040000000049dd4887.jpg",
          "verified": false
        },
        "metrics": {
          "likes": 48,
          "comments": 21,
          "shares": 5,
          "favorites": 10
        },
        "images": [
          "https://sns-webpic-qc.xhscdn.com/20261010/2d7c7c32da67d3c3d839!nd_dft_wlteh_webp_3"
        ]
      },
      // … 另有 14 条
    ]
  },
  "page": {
    "next_cursor": "c1.Ip12-f4dS4HmSDpdPex7WuLPBr1zJAbdhL_Wj8K0",
    "cursor_expires_at": "2026-10-12T19:43:26.000Z",
    "has_more": true,
    "returned": 15
  },
  "warnings": [],
  "meta": {
    "capability": "xiaohongshu.notes.search",
    "result_status": "complete",
    "fetched_at": "2026-10-12T18:43:26.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": {
      "lang": "capability",
      "metrics.views": "platform",
      "metrics.reposts": "platform",
      "author.followers": "capability",
      "hashtags": "capability",
      "mentions": "capability",
      "is_pinned": "capability",
      "post_id": "platform",
      "parent_id": "platform",
      "root_id": "platform"
    },
    "billing": {
      "amount": "0.02",
      "currency": "USD",
      "balance_after": "9.98"
    }
  }
}

取自 2026-10-12 18:43 UTC 录下的真实返回。名字、正文和编号是示例,链接也是,都不是录到的原文(页面不展示任何人的个人信息);数字是原样。长列表做了截断。请求号、游标和余额是示意。

小红书笔记搜索 · $0.0200 / 一次 · 参数、字段和报错见接口页 →

第 2 步:小红书笔记评论

把笔记编号放进 id,取一页一级评论。要下一页,把 page.next_cursor 作为 cursor 再调一次。

curl -G "https://api.dataxapi.com/v1/xiaohongshu/notes/comments/list" \
  --data-urlencode "id=6a9c5884000000002b002d95" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
# pip install dataxapi
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.xiaohongshu.notes.comments.list(id="6a9c5884000000002b002d95")
print(result["data"]["items"])
// npm i @dataxapi/sdk
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.xiaohongshu.notes.comments.list({ id: "6a9c5884000000002b002d95" });
console.log(result.data.items);
dataxapi call xiaohongshu.notes.comments.list id=6a9c5884000000002b002d95
录制的返回
{
  "code": "ok",
  "request_id": "fd58d135-ef6e-4271-869d-fbb8d27199ce",
  "data": {
    "items": [
      {
        "id": "68d0607400000000edd345fe",
        "text": "我上次也踩了这个坑哈哈",
        "published_at": "2026-10-11T13:28:37.000Z",
        "author": {
          "id": "6da35157000000005fdd7a79",
          "username": "nanfeng_0721",
          "name": "南边的风",
          "avatar_url": "https://sns-avatar-qc.xhscdn.com/avatar/65250da200000000167ab981.jpg"
        },
        "metrics": { "likes": 0, "comments": 0 },
        "post_id": "6696eaf60000000000904fc3",
        "parent_id": null,
        "root_id": null
      },
      // … 另有 9 条
    ]
  },
  "page": {
    "next_cursor": "c1.lk7Qsam6A9ERrgAE_Wv8XIQJG0N-AN_z2Xy0yA78",
    "cursor_expires_at": "2026-10-12T19:43:50.000Z",
    "has_more": true,
    "returned": 10
  },
  "warnings": [],
  "meta": {
    "capability": "xiaohongshu.notes.comments.list",
    "result_status": "complete",
    "fetched_at": "2026-10-12T18:43:50.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": { "url": "platform" },
    "billing": {
      "amount": "0.02",
      "currency": "USD",
      "balance_after": "9.98"
    }
  }
}

取自 2026-10-12 18:43 UTC 录下的真实返回。名字、正文和编号是示例,链接也是,都不是录到的原文(页面不展示任何人的个人信息);数字是原样。长列表做了截断。请求号、游标和余额是示意。

小红书笔记评论 · $0.0200 / 一次 · 参数、字段和报错见接口页 →

示例花多少钱

一页搜索结果,再取前 10 篇笔记各一页评论

接口调用次数单价小计
小红书笔记搜索1$0.0200$0.0200
小红书笔记评论10$0.0200$0.20
合计11$0.22

价格是生成本页时的现行价格。失败的调用不收费。

在 AI 里做(MCP)

把 DataXAPI 接进你的 AI 客户端,只要接一次。之后直接说要什么,代理自己找到这些接口、看好价格,用你的余额调用。

这样说: 在小红书搜“咖啡”,取前 10 篇笔记的第一页评论,整理成一张表:笔记标题、评论、点赞数。
代理发给 call 工具的参数
{
  "capability": "xiaohongshu.notes.search",
  "query": "咖啡",
  "idempotency_key": "<a new UUID>"
}

登录后复制带你 Key 的接入提示词了解 MCP 服务 →

用 Skill 做

为什么用 DataXAPI

  • 稳定:近 30 天接口可用 99.9%,状态页公开,可以自己核对。
  • 快:近 7 天付费调用的中位耗时 1.3 秒(2026-11-06 统计)。
  • 省 token:小红书的 21 个接口各取一份录制的真实返回,平台原始 JSON 合计 48 万 token,AI 通过 DataXAPI 的 MCP 读到的只有 3.6 万 token,少 92%;直接调接口拿到的 JSON 也少 85%(2026-11-06 统计)。所有平台同一种格式:作者在 author,互动数在 metrics,翻页用 page.next_cursor,换平台不用重写解析。
  • 先看再用:每个接口的页面上都有一份录制的真实返回,字段一目了然。
  • 花钱可控:失败不收费;每把 Key 能设金额上限,X-Max-Price 限定一次最多花多少,同一个 Idempotency-Key 24 小时内不重复扣费。
  • 接 AI 方便:远程 MCP 服务已在 MCP 官方登记处登记(com.dataxapi/mcp),Claude、Cursor、ChatGPT 都能直接用。
  • 免费试用,最多 333 次,不用绑卡。

要知道的

  • 评论一页通常 10 条,只有一级评论;回复用 xiaohongshu.comments.replies.list。page.next_cursor 一小时内有效。
  • 笔记编号是 24 位十六进制;只有链接或分享文案时,原样放进 url。不用小红书账号和 Cookie。
  • 不写代码也行:把 DataXAPI 接进 Claude 或 ChatGPT,用下面“在 AI 里做”的那句话。

完整脚本

上面这件事写成一个能直接跑的脚本:Python,用 SDK,Key 从 DATAXAPI_API_KEY 读。它写出一个 CSV 文件,最后打印调了几次、取到几条、扣了多少。

Python
# pip install dataxapi
# export DATAXAPI_API_KEY=dx_...   (your key)
import csv
from decimal import Decimal
from dataxapi import DataXAPI

dx = DataXAPI()
calls, fetched, charged = 0, 0, Decimal("0")

def run(capability, params):
    """One call; counts it and what it was charged."""
    global calls, charged
    result = dx.call(capability, params)
    calls += 1
    charged += Decimal(str(result["meta"]["billing"]["amount"]))
    return result

QUERY = "咖啡"
NOTES = 10

# 1. A page of notes for the search terms.
notes = run("xiaohongshu.notes.search", {"query": QUERY})["data"]["items"][:NOTES]

# 2. The first page of comments under each note.
rows = []
for note in notes:
    for comment in run("xiaohongshu.notes.comments.list", {"id": note["id"]})["data"]["items"]:
        rows.append([note.get("title"), note["metrics"].get("likes"), comment.get("text"), comment["metrics"].get("likes"), comment.get("published_at")])

fetched = len(rows)
with open("xiaohongshu-notes-comments.csv", "w", newline="", encoding="utf-8") as file:
    csv.writer(file).writerows([["note_title", "note_likes", "comment", "comment_likes", "published_at"], *rows])

print(f"calls: {calls}, items: {fetched}, charged: ${charged}")