Skip to content

feat(xiaohongshu): add publish command for 图文 note automation#276

Merged
jackwener merged 1 commit intojackwener:mainfrom
stone16:feat/xiaohongshu-publish
Mar 23, 2026
Merged

feat(xiaohongshu): add publish command for 图文 note automation#276
jackwener merged 1 commit intojackwener:mainfrom
stone16:feat/xiaohongshu-publish

Conversation

@stone16
Copy link
Contributor

@stone16 stone16 commented Mar 23, 2026

Summary

Adds opencli xiaohongshu publish — automates posting 图文 (image + text) notes to Xiaohongshu via creator center UI.

Usage

```bash
opencli xiaohongshu publish
--title "我的旅行日记"
"正文内容,风景很美 🌸"
--images /tmp/photo1.jpg,/tmp/photo2.jpg
--topics 旅行,生活
```

How it works

  1. Navigates to `creator.xiaohongshu.com/publish/publish`
  2. Selects 图文 note type tab if needed
  3. Image upload — reads local files as base64, injects into `` via DataTransfer + Object.defineProperty override (no `setInputFiles` required)
  4. Fills title + body via `document.execCommand('insertText')`
  5. Adds topics by simulating the search UI
  6. Clicks 发布笔记 (or 存草稿 with `--draft`)
  7. Verifies success via URL navigation or toast text

Arguments

Argument Required Description
`--title` 笔记标题, max 20 chars
`` 笔记正文 (positional)
`--images` Comma-separated image paths (jpg/png/gif/webp, max 9)
`--topics` Comma-separated hashtag names (no `#`)
`--draft` Save as draft instead of publishing

Requirements

Browser session logged into `creator.xiaohongshu.com` (Strategy.COOKIE)

Adds `opencli xiaohongshu publish` which automates posting a 图文 (image+text)
note via the creator center UI (creator.xiaohongshu.com/publish/publish).

Features:
- --title (required, max 20 chars)
- positional content argument
- --images comma-separated local file paths (jpg/png/gif/webp, max 9)
- --topics comma-separated hashtag names (without #)
- --draft flag to save as draft instead of publishing

Image upload uses DataTransfer injection into the file input element, converting
local files to base64 in Node.js and creating File blobs in the browser context.
Text fields use document.execCommand('insertText') for contenteditable editors.
Graceful debug screenshots on failure (/tmp/xhs_publish_*_debug.png).

Requires: opencli browser session logged into creator.xiaohongshu.com.
@jackwener jackwener merged commit a6d993f into jackwener:main Mar 23, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants