xiaohongshu-justoneapi

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

小红书数据采集 —— JustOneAPI

Xiaohongshu Data Collection —— JustOneAPI

使用 JustOneAPI 调用小红书接口抓取数据。
Use JustOneAPI to call Xiaohongshu interfaces for data crawling.

前置:获取 Token

Prerequisite: Get Token

所有接口均通过 query 参数
token
鉴权。按以下优先级获取 token:
  1. 从当前目录向上逐级查找
    .env
    文件,匹配
    JUSTONEAPI_TOKEN
    JUST_ONE_API_TOKEN
  2. 读取系统环境变量
    JUSTONEAPI_TOKEN
    JUST_ONE_API_TOKEN
  3. 均未找到则报错退出,提示用户在
    .env
    中添加 token
生成代码时,token 应从环境变量读取,不要硬编码到代码中:
JUSTONEAPI_TOKEN=your_token_here
All interfaces are authenticated via the query parameter
token
. Obtain the token in the following priority order:
  1. Search for
    .env
    files upwards from the current directory, matching
    JUSTONEAPI_TOKEN
    or
    JUST_ONE_API_TOKEN
  2. Read the system environment variables
    JUSTONEAPI_TOKEN
    or
    JUST_ONE_API_TOKEN
  3. If neither is found, exit with an error and prompt the user to add the token in
    .env
When generating code, the token should be read from environment variables and not hard-coded into the code:
JUSTONEAPI_TOKEN=your_token_here

错误码(所有接口通用)

Error Codes (Applicable to All Interfaces)

⚠️
code
响应体中,不是 HTTP 状态码。HTTP 200 也须检查
code
code
含义处理策略
0
成功正常处理
100
Token 无效或已失效提示用户检查 token
301
采集失败自动重试,间隔 2-3 秒,最多 3 次
302
超出速率限制降低请求频率,等待后重试
303
超出每日配额告知用户当日配额已用尽
400
参数错误检查必填参数是否缺失或格式有误
500
服务器内部错误稍后重试,持续则反馈 JustOneAPI
600
权限不足告知用户当前 token 无此接口权限
601
余额不足告知用户需在 JustOneAPI 充值
⚠️
code
is in the response body, not the HTTP status code. Even if HTTP 200 is returned,
code
must be checked.
code
MeaningHandling Strategy
0
SuccessProcess normally
100
Invalid or expired TokenPrompt user to check the token
301
Collection failedAuto-retry with an interval of 2-3 seconds, maximum 3 times
302
Rate limit exceededReduce request frequency and retry after waiting
303
Daily quota exceededInform user that the daily quota has been used up
400
Parameter errorCheck if required parameters are missing or formatted incorrectly
500
Internal server errorRetry later; if the issue persists, feedback to JustOneAPI
600
Insufficient permissionsInform user that the current token has no access to this interface
601
Insufficient balanceInform user to recharge on JustOneAPI

接口目录

Interface Directory

根据用户意图,按需读取对应文件,不要自行重写脚本
用户意图接口定义脚本
搜索用户 / 发现博主 / 查账号
apis/search_users.md
scripts/search_users.py
抓取用户发布的笔记 / 内容分析 / 竞品监控
apis/get_user_posts.md
scripts/get_user_posts.py
搜索笔记 / 话题发现 / 关键词采集 / 舆情追踪
apis/search_notes.md
scripts/search_notes.py
抓取笔记评论 / 评论回复 / 舆情分析 / 情感分析
apis/get_note_comments.md
scripts/get_note_comments.py
Read the corresponding file according to the user's intent, do not rewrite scripts on your own.
User IntentInterface DefinitionScript
Search users / Discover bloggers / Check accounts
apis/search_users.md
scripts/search_users.py
Capture user-published notes / Content analysis / Competitor monitoring
apis/get_user_posts.md
scripts/get_user_posts.py
Search notes / Topic discovery / Keyword collection / Public opinion tracking
apis/search_notes.md
scripts/search_notes.py
Capture note comments / Comment replies / Public opinion analysis / Sentiment analysis
apis/get_note_comments.md
scripts/get_note_comments.py

运行方式

Running Methods

所有脚本统一使用
uv run
执行,无需手动安装依赖:
bash
undefined
All scripts are executed uniformly with
uv run
; no manual dependency installation is required:
bash
undefined

安装 uv(若尚未安装)

Install uv (if not installed yet)

直接运行,uv 自动处理依赖

Run directly, uv handles dependencies automatically

uv run scripts/search_users.py <keyword> [max_pages] [--output-dir DIR] uv run scripts/get_user_posts.py <user_id> [user_id2 ...] [--output-dir DIR] [--since YYYY-MM-DD] [--workers N] uv run scripts/search_notes.py <keyword> <max_pages> [--sort SORT] [--note-type TYPE] [--output-dir DIR] uv run scripts/get_note_comments.py <note_id> [note_id2 ...] [--output-dir DIR] [--sort latest|normal] [--max-top N] [--no-replies]
uv run scripts/search_users.py <keyword> [max_pages] [--output-dir DIR] uv run scripts/get_user_posts.py <user_id> [user_id2 ...] [--output-dir DIR] [--since YYYY-MM-DD] [--workers N] uv run scripts/search_notes.py <keyword> <max_pages> [--sort SORT] [--note-type TYPE] [--output-dir DIR] uv run scripts/get_note_comments.py <note_id> [note_id2 ...] [--output-dir DIR] [--sort latest|normal] [--max-top N] [--no-replies]

示例

Examples

uv run scripts/search_users.py 美妆博主 5 --output-dir ./output uv run scripts/get_user_posts.py 5b33a8556b58b74911b89949 5f279d91000000000100836c --output-dir ./output --since 2025-01-01 uv run scripts/search_notes.py 美妆 10 --sort popularity_descending --note-type _1 --output-dir ./output uv run scripts/search_notes.py 机车骑行 20 --sort time_descending --output-dir ./output uv run scripts/get_note_comments.py 65bf5360000000002c03f684 --output-dir ./output uv run scripts/get_note_comments.py 65bf5360000000002c03f684 --no-replies # 仅抓顶层评论 uv run scripts/get_note_comments.py 65bf5360000000002c03f684 --max-top 100 # 顶层评论达到 100 条即停止翻页 uv run scripts/get_note_comments.py 65bf5360000000002c03f684 --sort normal # 按默认排序拉取
undefined
uv run scripts/search_users.py 美妆博主 5 --output-dir ./output uv run scripts/get_user_posts.py 5b33a8556b58b74911b89949 5f279d91000000000100836c --output-dir ./output --since 2025-01-01 uv run scripts/search_notes.py 美妆 10 --sort popularity_descending --note-type _1 --output-dir ./output uv run scripts/search_notes.py 机车骑行 20 --sort time_descending --output-dir ./output uv run scripts/get_note_comments.py 65bf5360000000002c03f684 --output-dir ./output uv run scripts/get_note_comments.py 65bf5360000000002c03f684 --no-replies # Only capture top-level comments uv run scripts/get_note_comments.py 65bf5360000000002c03f684 --max-top 100 # Stop pagination when top-level comments reach 100 uv run scripts/get_note_comments.py 65bf5360000000002c03f684 --sort normal # Pull data in default sort order
undefined