Xiaohongshu Publisher
Automate publishing notes to Xiaohongshu (小红书) via the Creator Platform (creator.xiaohongshu.com) using browser CDP.
Prerequisites
- - Browser with CDP access (Chromium with
--remote-debugging-port) - User must be already logged in to Xiaohongshu (manual QR scan login required — automation is blocked by anti-bot detection)
- Chinese font installed (e.g.,
DroidSansFallbackFull.ttf) for cover image generation
Workflow
1. Verify Login Status
CODEBLOCK0
If not logged in, ask user to scan QR code manually. Phone number login is blocked by anti-automation detection.
2. Navigate to Publish Page
CODEBLOCK1
Wait for the editor to load. Look for the upload area and editor elements.
3. Upload Cover Image
Upload image via CDP DOM.setFileInputFiles:
CODEBLOCK2
⚠️ Cover Image Text Rendering: On systems without full CJK fonts, Chinese text in generated images may show as squares (□). Solutions:
- - Use
DroidSansFallbackFull.ttf for Chinese characters - Use a mixed font approach: CJK font for Chinese + DejaVu/system font for ASCII
- Always verify the image before uploading
4. Input Title
Use CDP Input.insertText for reliable Chinese text input (avoids encoding issues):
CODEBLOCK3
Title limit: 20 characters max.
5. Input Body Content
Target the ProseMirror editor:
CODEBLOCK4
Supports basic formatting. For hashtags, type #话题 and select from dropdown.
6. Publish
Click the publish button. Use coordinate-based click (Input.dispatchMouseEvent) if selector-based click fails:
CODEBLOCK5
7. Verify Publication
After publishing, check for:
- - Success: redirect to content management page
- Failure:
error_code=300031 means content was taken down (usually image issues)
Key Technical Details
- - Tab switching:
.creator-tab:not(.active) CSS selector for switching between image/video modes - Anti-automation: Xiaohongshu has aggressive bot detection. Avoid rapid automated actions. Add delays between steps.
- Content moderation: Posts may be auto-reviewed and taken down. Check content management page for status.
- Image requirements: Recommended ratio 3:4, minimum 960x1280px for best display
Troubleshooting
| Problem | Solution |
|---|
| Login blocked | Use QR code scan (manual), not phone number |
| Chinese text shows □ in images |
Use DroidSansFallbackFull.ttf font |
| Post taken down (300031) | Check cover image for rendering issues |
| Title input garbled | Use
Input.insertText CDP method |
| Publish button unresponsive | Use coordinate-based mouse events |
| Cannot delete posts via API | Use web UI manually; API returns 404 |
Reference: User Profile Access
To fetch user profile info:
CODEBLOCK6
小红书发布器
通过浏览器CDP,在创作者平台(creator.xiaohongshu.com)上自动发布笔记到小红书。
前置条件
- - 支持CDP访问的浏览器(使用 --remote-debugging-port 参数的Chromium)
- 用户必须已登录小红书(需要手动扫码登录——自动化操作会被反爬检测拦截)
- 安装中文字体(例如 DroidSansFallbackFull.ttf)用于封面图生成
工作流程
1. 验证登录状态
浏览器打开 → https://creator.xiaohongshu.com
浏览器截图 → 检查是否已登录(查找用户头像/名称)
如果未登录,请用户手动扫码。手机号登录会被反自动化检测拦截。
2. 导航到发布页面
浏览器打开 → https://creator.xiaohongshu.com/publish/publish
等待编辑器加载完成。查找上传区域和编辑器元素。
3. 上传封面图
通过CDP的 DOM.setFileInputFiles 上传图片:
javascript
// 查找文件输入元素
const fileInput = document.querySelector(input[type=file]);
// 使用CDP设置文件
DOM.setFileInputFiles({ files: [/path/to/image.jpg], objectId: ... })
⚠️ 封面图文字渲染:在未安装完整中日韩字体的系统上,生成的图片中的中文文字可能显示为方框(□)。解决方案:
- - 使用 DroidSansFallbackFull.ttf 显示中文字符
- 采用混合字体方案:中文使用中日韩字体 + ASCII使用DejaVu/系统字体
- 上传前务必验证图片效果
4. 输入标题
使用CDP的 Input.insertText 实现可靠的中文文本输入(避免编码问题):
javascript
// 先点击标题输入框
// 然后使用CDP:
Input.insertText({ text: 你的标题 })
标题限制:最多20个字符。
5. 输入正文内容
定位到ProseMirror编辑器:
javascript
// 选择器:.tiptap.ProseMirror(可编辑div)
// 点击聚焦,然后使用Input.insertText
支持基本格式。输入话题标签时,键入 #话题 并从下拉列表中选择。
6. 发布
点击发布按钮。如果基于选择器的点击失败,则使用基于坐标的点击(Input.dispatchMouseEvent):
javascript
Input.dispatchMouseEvent({ type: mousePressed, x: X, y: Y, button: left, clickCount: 1 })
Input.dispatchMouseEvent({ type: mouseReleased, x: X, y: Y, button: left, clickCount: 1 })
7. 验证发布结果
发布后,检查以下情况:
- - 成功:跳转到内容管理页面
- 失败:error_code=300031 表示内容被下架(通常是图片问题)
关键技术细节
- - 标签切换:使用 .creator-tab:not(.active) CSS选择器切换图片/视频模式
- 反自动化:小红书有严格的反爬检测。避免快速自动化操作。在步骤之间添加延迟。
- 内容审核:帖子可能会被自动审核并下架。查看内容管理页面了解状态。
- 图片要求:推荐比例3:4,最低960x1280像素以获得最佳显示效果
故障排除
| 问题 | 解决方案 |
|---|
| 登录被拦截 | 使用二维码扫码(手动),不要用手机号 |
| 图片中中文显示为□ |
使用DroidSansFallbackFull.ttf字体 |
| 帖子被下架(300031) | 检查封面图是否存在渲染问题 |
| 标题输入乱码 | 使用 Input.insertText CDP方法 |
| 发布按钮无响应 | 使用基于坐标的鼠标事件 |
| 无法通过API删除帖子 | 使用网页UI手动操作;API返回404 |
参考:用户资料访问
获取用户资料信息:
浏览器打开 → https://www.xiaohongshu.com/user/profile/{userId}
浏览器截图 → 提取粉丝数、笔记数等