Python guide: search Xiaohongshu notes and export comments to CSV
Fetch Xiaohongshu notes by keyword and paginate comments straight into CSV in under 40 lines of Python—using X-Max-Price guardrails and paying only on successful calls.
Endpoints used
| Endpoint | Path | Price |
|---|---|---|
| Xiaohongshu note search | GET /v1/xiaohongshu/notes/search |
$0.02 |
| Xiaohongshu note | GET /v1/xiaohongshu/notes/get |
$0.02 |
| Xiaohongshu note comments | GET /v1/xiaohongshu/notes/comments/list |
$0.02 |
| Xiaohongshu comment replies | GET /v1/xiaohongshu/notes/comments/replies/list |
$0.02 |
Steps
1. Export your API key
Sign up in the console for $0.10 free trial credit, create a key, and run export FEEDMCP_API_KEY="fmk_live_…".
2. Search notes to get note IDs
Call GET /v1/xiaohongshu/notes/search ($0.02/call) to list top matching notes.
3. Paginate comments into CSV
Loop over GET /v1/xiaohongshu/notes/comments/list ($0.02/page) passing page.next_cursor until you hit your page cap.
Complete code
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)
Cost estimate
One full run (1 search + 3 comment pages = 4 calls) costs $0.08, covered by the $0.10 free sign-up credit.
Questions
How much does it cost to run this guide?
One full run (1 search + 3 comment pages = 4 calls) costs $0.08, covered by the $0.10 free sign-up credit.
Can I do this without writing code?
Yes. Install the FeedMCP MCP server in Claude, Cursor or Cherry Studio and run the same workflow in plain language.
More guides
- Python guide: Douyin trending, video comments and Xingtu creator rates
- Python guide: fetch WeChat Official Account articles, stats and comments
- Extract video transcripts from YouTube, TikTok, Instagram, X & Meta Ads for LLMs
- Monitor competitor ads across Meta, Google, LinkedIn & TikTok in one script
- Mine product pain points across TikTok, Reddit, Xiaohongshu & Douyin with MCP
- Low-cost X (Twitter) monitoring with per-item pricing ($0.0003/item)
- Production guardrails for AI agents: spend caps, X-Max-Price & idempotency