---
title: "用 Python 调用小红书 API：搜索笔记并翻页导出评论到 CSV | FeedMCP"
description: "完整 Python 示例：免 Cookie、免 461 滑块调用 FeedMCP 小红书接口，按游标翻页导出笔记评论到 CSV。"
canonical: "https://feedmcp.com/zh/guides/xiaohongshu-api-python/"
---
<p class="crumbs"><a href="/zh/guides/">技术指南</a></p>

# 用 Python 调用小红书 API：搜索笔记并翻页导出评论到 CSV

本指南演示如何用不到 40 行 Python 代码调用 FeedMCP 小红书接口：先按关键词搜笔记，再按 `page.next_cursor` 翻页抓取评论并导出为 CSV，全程带 `X-Max-Price` 控价和失败不扣费保障。

## 涉及的接口与价格

| 接口 | 路径 | 单价 |
| --- | --- | --- |
| [小红书笔记搜索](/zh/apis/xiaohongshu/notes/search/) | `GET /v1/xiaohongshu/notes/search` | $0.02 |
| [小红书笔记详情](/zh/apis/xiaohongshu/notes/get/) | `GET /v1/xiaohongshu/notes/get` | $0.02 |
| [小红书笔记评论](/zh/apis/xiaohongshu/notes/comments/list/) | `GET /v1/xiaohongshu/notes/comments/list` | $0.02 |
| [小红书评论的回复](/zh/apis/xiaohongshu/notes/comments/replies/list/) | `GET /v1/xiaohongshu/notes/comments/replies/list` | $0.02 |

## 实现步骤

### 1. 获取 API Key 并设置环境变量

在[控制台](/zh/console/keys/)注册拿 $0.10 免费额度并建一把 Key，执行 `export FEEDMCP_API_KEY="fmk_live_…"`。

### 2. 搜索目标笔记并拿到 note_id

调用 `GET /v1/xiaohongshu/notes/search`（$0.02/次）拿到按互动排序的笔记列表。

### 3. 按游标翻页抓评论并写入 CSV

循环调用 `GET /v1/xiaohongshu/notes/comments/list`（$0.02/页），把 `page.next_cursor` 传给下一页直到满足页数上限。

## 完整代码示例

```python
import csv, os, uuid, requests

API = "https://api.feedmcp.com"
HEADERS = {
    "Authorization": f"Bearer {os.environ['FEEDMCP_API_KEY']}",
    "X-Max-Price": "0.02",
}

def search_notes(query: str):
    r = requests.get(f"{API}/v1/xiaohongshu/notes/search", params={"query": query}, headers=HEADERS, timeout=30)
    r.raise_for_status()
    return r.json()["data"]["items"]

def export_comments(note_id: str, max_pages: int = 3, out_csv: str = "xhs_comments.csv"):
    cursor, rows = None, []
    for _ in range(max_pages):
        params = {"id": note_id, **({"cursor": cursor} if cursor else {})}
        headers = {**HEADERS, "Idempotency-Key": str(uuid.uuid4())}
        body = requests.get(f"{API}/v1/xiaohongshu/notes/comments/list", params=params, headers=headers, timeout=30).json()
        if body.get("code") != "ok":
            break
        rows.extend(body["data"]["items"])
        cursor = (body.get("page") or {}).get("next_cursor")
        if not cursor:
            break
    with open(out_csv, "w", newline="", encoding="utf-8-sig") as f:
        w = csv.writer(f)
        w.writerow(["id", "author", "likes", "created_at", "text"])
        for c in rows:
            w.writerow([c["id"], (c.get("author") or {}).get("name"), c.get("likes"), c.get("created_at"), c.get("text")])
    print(f"Saved {len(rows)} comments to {out_csv}")

if __name__ == "__main__":
    notes = search_notes("camping tent")
    if notes:
        export_comments(notes[0]["id"], max_pages=3)
```

## 费用估算

上述脚本运行一次（1 次搜索 + 3 页评论）共 4 次调用，总计 **$0.08**，使用新用户免费送的 $0.10 额度即可完整跑通。

## 常见问题

### 跑完这份教程大概要花多少钱？

上述脚本运行一次（1 次搜索 + 3 页评论）共 4 次调用，总计 **$0.08**，使用新用户免费送的 $0.10 额度即可完整跑通。

### 没有代码基础，能在 AI 里直接完成同样的事吗？

可以。把 FeedMCP 的 [MCP 服务](/zh/mcp/)装进 Claude、Cursor 或 Cherry Studio 后，用自然语言即可完成同样的查询与汇总。

## 更多指南

- [用 Python 调用抖音 API：拉热榜、抓评论与查星图达人报价](/zh/guides/douyin-api-python/)
- [用 Python 自动采集微信公众号历史文章、阅读点赞数与留言](/zh/guides/wechat-mp-articles-python/)
- [多平台视频字幕提取指南：把 TikTok、YouTube、Instagram、X 视频喂给大模型](/zh/guides/tiktok-youtube-transcripts-ai/)
- [跨平台竞品广告监控指南：一套脚本盯 Meta、Google、LinkedIn 和 TikTok 广告库](/zh/guides/competitor-ad-library-monitor/)
- [用 AI + MCP 做跨平台评论区痛点挖掘（TikTok + Reddit + 小红书 + 抖音）](/zh/guides/social-comment-pain-point-mining/)
- [X（Twitter）按条计费省钱指南：如何以 $0.0003/条 搭建低成本监控流](/zh/guides/x-twitter-pay-per-item-guide/)
- [生产级 AI Agent 防花超指南：Key 上限、X-Max-Price 与 Idempotency-Key](/zh/guides/ai-agent-cost-control/)

---

网页版: https://feedmcp.com/zh/guides/xiaohongshu-api-python/
