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- 从当前目录向上逐级查找 文件,匹配
.env或JUSTONEAPI_TOKENJUST_ONE_API_TOKEN - 读取系统环境变量 或
JUSTONEAPI_TOKENJUST_ONE_API_TOKEN - 均未找到则报错退出,提示用户在 中添加 token
.env
生成代码时,token 应从环境变量读取,不要硬编码到代码中:
JUSTONEAPI_TOKEN=your_token_hereAll interfaces are authenticated via the query parameter . Obtain the token in the following priority order:
token- Search for files upwards from the current directory, matching
.envorJUSTONEAPI_TOKENJUST_ONE_API_TOKEN - Read the system environment variables or
JUSTONEAPI_TOKENJUST_ONE_API_TOKEN - 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)
⚠️在响应体中,不是 HTTP 状态码。HTTP 200 也须检查code。code
| 含义 | 处理策略 |
|---|---|---|
| 成功 | 正常处理 |
| Token 无效或已失效 | 提示用户检查 token |
| 采集失败 | 自动重试,间隔 2-3 秒,最多 3 次 |
| 超出速率限制 | 降低请求频率,等待后重试 |
| 超出每日配额 | 告知用户当日配额已用尽 |
| 参数错误 | 检查必填参数是否缺失或格式有误 |
| 服务器内部错误 | 稍后重试,持续则反馈 JustOneAPI |
| 权限不足 | 告知用户当前 token 无此接口权限 |
| 余额不足 | 告知用户需在 JustOneAPI 充值 |
⚠️is in the response body, not the HTTP status code. Even if HTTP 200 is returned,codemust be checked.code
| Meaning | Handling Strategy |
|---|---|---|
| Success | Process normally |
| Invalid or expired Token | Prompt user to check the token |
| Collection failed | Auto-retry with an interval of 2-3 seconds, maximum 3 times |
| Rate limit exceeded | Reduce request frequency and retry after waiting |
| Daily quota exceeded | Inform user that the daily quota has been used up |
| Parameter error | Check if required parameters are missing or formatted incorrectly |
| Internal server error | Retry later; if the issue persists, feedback to JustOneAPI |
| Insufficient permissions | Inform user that the current token has no access to this interface |
| Insufficient balance | Inform user to recharge on JustOneAPI |
接口目录
Interface Directory
根据用户意图,按需读取对应文件,不要自行重写脚本。
| 用户意图 | 接口定义 | 脚本 |
|---|---|---|
| 搜索用户 / 发现博主 / 查账号 | | |
| 抓取用户发布的笔记 / 内容分析 / 竞品监控 | | |
| 搜索笔记 / 话题发现 / 关键词采集 / 舆情追踪 | | |
| 抓取笔记评论 / 评论回复 / 舆情分析 / 情感分析 | | |
Read the corresponding file according to the user's intent, do not rewrite scripts on your own.
| User Intent | Interface Definition | Script |
|---|---|---|
| Search users / Discover bloggers / Check accounts | | |
| Capture user-published notes / Content analysis / Competitor monitoring | | |
| Search notes / Topic discovery / Keyword collection / Public opinion tracking | | |
| Capture note comments / Comment replies / Public opinion analysis / Sentiment analysis | | |
运行方式
Running Methods
所有脚本统一使用 执行,无需手动安装依赖:
uv runbash
undefinedAll scripts are executed uniformly with ; no manual dependency installation is required:
uv runbash
undefined安装 uv(若尚未安装)
Install uv (if not installed yet)
curl -LsSf https://astral.sh/uv/install.sh | sh
curl -LsSf https://astral.sh/uv/install.sh | sh
直接运行,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 # 按默认排序拉取
undefineduv 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