Implement Xiaohongshu Web API calls through Playwright browser automation, with no official API Key required.
Prerequisites
- Install dependencies:
pip install -r requirements.txt && playwright install chromium - Login is required on first use:
python xhs.py login(will open the browser, scan the QR code manually)
Verify login status:
python skills/xhs-cli/xhs.py me
Trigger conditions
Use this Skill in the following situations:
- The user wants to search Xiaohongshu content
- The user wants to view the details or comments of a note
- The user wants to learn about a Xiaohongshu user's homepage
- The user wants to view their own account data
- The user wants to publish an image and text note
Search notes
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 # 只搜视频
Note details and comments
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 and xsec_token are obtained from the search results.
User information
python skills/xhs-cli/xhs.py me # 当前登录用户
python skills/xhs-cli/xhs.py user <user_id> # 查看用户主页
python skills/xhs-cli/xhs.py unread # 未读通知
Account data
python skills/xhs-cli/xhs.py stats # 所有帖子数据概览
python skills/xhs-cli/xhs.py stats --detail # 含每篇帖子详情
Needs to be configured in config.yaml account_name and search_keyword。
Publish note
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 # 跳过确认
Draft file format:
## 标题
帖子标题
## 正文
正文内容...
## 话题标签
#标签1 #标签2 #标签3
Typical workflow
"Help me search for content about XX on Xiaohongshu"
search "XX"search- For notes of interest
note <id> <token>view details + comments - Summarize and return
"See how my account data is doing"
stats --detailget all post data- Analyze trends and give suggestions
"Help me analyze this competitor account"
user <user_id>get homepage information- Search for this user's posts
- For viral posts
commentscheck comment section feedback
Notes
- On first use, you must
loginscan the QR code to log in; the Cookie is saved indata/xhs_cookie.txt - Xiaohongshu has anti-scraping mechanisms; high-frequency requests may trigger a CAPTCHA, so it is recommended to leave intervals between operations
- In the search results,
xsec_tokenis time-sensitive; once expired, you need to search again - Newly published posts may take several hours to appear in the search results
- The publishing feature requires an additional login to the Creator Center:
xhs_publish.py login