xhs-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese小红书 CLI
Xiaohongshu (XHS) CLI
通过 Playwright 浏览器自动化实现小红书 Web API 调用,无需官方 API Key。
Realize Xiaohongshu Web API calls via Playwright browser automation, no official API Key required.
前置条件
Prerequisites
- 安装依赖:
pip install -r requirements.txt && playwright install chromium - 首次使用需登录:(会打开浏览器,手动扫码)
python xhs.py login
验证登录状态:
bash
python skills/xhs-cli/xhs.py me- Install dependencies:
pip install -r requirements.txt && playwright install chromium - Log in for the first use: (a browser will open, scan the QR code manually)
python xhs.py login
Verify login status:
bash
python skills/xhs-cli/xhs.py me触发条件
Trigger Conditions
以下情况使用此 Skill:
- 用户要搜索小红书内容
- 用户要查看某篇笔记的详情或评论
- 用户要了解某个小红书用户的主页
- 用户要查看自己的账号数据
- 用户要发布图文笔记
Use this Skill in the following scenarios:
- Users want to search Xiaohongshu content
- Users want to view details or comments of a note
- Users want to learn about a Xiaohongshu user's homepage
- Users want to check their own account data
- Users want to publish image-text notes
搜索笔记
Search Notes
bash
python skills/xhs-cli/xhs.py search "关键词"
python skills/xhs-cli/xhs.py search "关键词" --sort time # 按时间排序
python skills/xhs-cli/xhs.py search "关键词" --type video # 只搜视频bash
python skills/xhs-cli/xhs.py search "keywords"
python skills/xhs-cli/xhs.py search "keywords" --sort time # Sort by time
python skills/xhs-cli/xhs.py search "keywords" --type video # Search only videos笔记详情和评论
Note Details and Comments
bash
python skills/xhs-cli/xhs.py detail <note_id> <xsec_token> # 笔记详情
python skills/xhs-cli/xhs.py comments <note_id> <xsec_token> # 评论列表
python skills/xhs-cli/xhs.py note <note_id> <xsec_token> # 详情 + 评论note_id 和 xsec_token 从搜索结果中获取。
bash
python skills/xhs-cli/xhs.py detail <note_id> <xsec_token> # Note details
python skills/xhs-cli/xhs.py comments <note_id> <xsec_token> # Comment list
python skills/xhs-cli/xhs.py note <note_id> <xsec_token> # Details + commentsnote_id and xsec_token are obtained from search results.
用户信息
User Information
bash
python skills/xhs-cli/xhs.py me # 当前登录用户
python skills/xhs-cli/xhs.py user <user_id> # 查看用户主页
python skills/xhs-cli/xhs.py unread # 未读通知bash
python skills/xhs-cli/xhs.py me # Currently logged-in user
python skills/xhs-cli/xhs.py user <user_id> # View user homepage
python skills/xhs-cli/xhs.py unread # Unread notifications账号数据
Account Data
bash
python skills/xhs-cli/xhs.py stats # 所有帖子数据概览
python skills/xhs-cli/xhs.py stats --detail # 含每篇帖子详情需要在 config.yaml 中配置 和 。
account_namesearch_keywordbash
python skills/xhs-cli/xhs.py stats # Overview of all post data
python skills/xhs-cli/xhs.py stats --detail # Include details of each postNeed to configure and in config.yaml.
account_namesearch_keyword发布笔记
Publish Notes
bash
python skills/xhs-cli/xhs_publish.py login # 创作者中心登录
python skills/xhs-cli/xhs_publish.py publish --draft draft.md --images a.jpg b.jpg # 发布
python skills/xhs-cli/xhs_publish.py publish --draft draft.md --images a.jpg --auto # 跳过确认草稿文件格式:
markdown
undefinedbash
python skills/xhs-cli/xhs_publish.py login # Creator Center login
python skills/xhs-cli/xhs_publish.py publish --draft draft.md --images a.jpg b.jpg # Publish
python skills/xhs-cli/xhs_publish.py publish --draft draft.md --images a.jpg --auto # Skip confirmationDraft file format:
markdown
undefined标题
Title
帖子标题
Post title
正文
Body
正文内容...
Body content...
话题标签
Hashtags
#标签1 #标签2 #标签3
undefined#tag1 #tag2 #tag3
undefined典型工作流
Typical Workflows
「帮我搜一下小红书上关于 XX 的内容」
"Help me search for content about XX on Xiaohongshu"
- 搜索
search "XX" - 对感兴趣的笔记 查看详情+评论
note <id> <token> - 总结返回
- to search
search "XX" - Use for interesting notes to view details + comments
note <id> <token> - Summarize and return
「看看我的账号数据怎么样」
"How is my account data?"
- 获取全部帖子数据
stats --detail - 分析趋势,给出建议
- to get all post data
stats --detail - Analyze trends and give suggestions
「帮我分析一下这个竞品账号」
"Help me analyze this competitor account"
- 获取主页信息
user <user_id> - 搜索该用户的帖子
- 对爆款帖 看评论区反馈
comments
- to get homepage information
user <user_id> - Search for the user's posts
- Use on popular posts to check comment feedback
comments
注意事项
Notes
- 首次使用必须 扫码登录,Cookie 保存在
logindata/xhs_cookie.txt - 小红书有反爬机制,高频请求可能触发验证码,建议操作间留间隔
- 搜索结果中的 有时效性,过期需重新搜索
xsec_token - 新发的帖子可能数小时后才出现在搜索结果中
- 发布功能需要额外登录创作者中心:
xhs_publish.py login
- Must and scan the QR code for the first use, cookies are saved in
logindata/xhs_cookie.txt - Xiaohongshu has anti-crawling mechanisms, high-frequency requests may trigger verification codes, it is recommended to leave intervals between operations
- The in search results has a validity period, re-search if it expires
xsec_token - Newly posted notes may appear in search results after a few hours
- The publishing function requires additional login to the Creator Center:
xhs_publish.py login