SuperAPI AI Directory

xhs-cli

Marketing & growth

View repository

Updated 10-15 08:50

About this skill

Xiaohongshu CLI

Implement Xiaohongshu Web API calls through Playwright browser automation, with no official API Key required.

Prerequisites

  1. Install dependencies:pip install -r requirements.txt && playwright install chromium
  2. 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"

  1. search "XX" search
  2. For notes of interest note <id> <token> view details + comments
  3. Summarize and return

"See how my account data is doing"

  1. stats --detail get all post data
  2. Analyze trends and give suggestions

"Help me analyze this competitor account"

  1. user <user_id> get homepage information
  2. Search for this user's posts
  3. For viral posts comments check comment section feedback

Notes

  • On first use, you must login scan the QR code to log in; the Cookie is saved in data/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_token is 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