post-to-xhs

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

小红书内容发布

Xiaohongshu Content Publishing

根据用户输入自动判断发布方式和发布模式,简化发布流程。
Automatically determine the publishing method and mode based on user input to simplify the publishing process.

发布模式

Publishing Modes

  • 上传图文(默认):图片 + 短文,适合日常分享
  • 写长文:长篇文章 + 排版模板选择,适合深度内容。用户明确说"发长文"时使用
  • Image-Text Upload (Default): Images + Short Text, suitable for daily sharing
  • Long Article Writing: Long-form Article + Typesetting Template Selection, suitable for in-depth content. Use this mode when the user explicitly says "post long article"

工作流程

Workflow

用户输入
    ├─ 完整内容 + 图片/图片URL → 判断模式 → 发布流程
    └─ 网页 URL → WebFetch 提取内容和图片
                      ├─ 有图片 → 适当总结内容 → 判断模式 → 发布流程
                      └─ 无图片 → 提示用户手动下载图片
                                  └─ 用户提供图片后 → 发布流程
User Input
    ├─ Complete Content + Images/Image URLs → Determine Mode → Publishing Process
    └─ Webpage URL → WebFetch Extract Content and Images
                      ├─ With Images → Summarize Content Appropriately → Determine Mode → Publishing Process
                      └─ Without Images → Prompt User to Download Images Manually
                                  └─ After User Provides Images → Publishing Process

Step 1: 判断输入类型

Step 1: Determine Input Type

根据用户输入判断:
  • 完整内容模式:用户提供了标题、正文内容、以及图片(本地路径或URL)
  • URL 提取模式:用户只提供了一个网页 URL
如果不确定,询问用户。
Judge based on user input:
  • Complete Content Mode: User provides title, body content, and images (local path or URL)
  • URL Extraction Mode: User only provides a webpage URL
If unsure, ask the user.

Step 2: 处理内容

Step 2: Process Content

完整内容模式

Complete Content Mode

直接使用用户提供的标题和正文,跳到 Step 3。
Directly use the title and body provided by the user, proceed to Step 3.

URL 提取模式

URL Extraction Mode

  1. 使用 WebFetch 提取网页内容
  2. 提取关键信息:标题、正文、图片URL
  3. 适当总结内容,保持:
    • 关键信息完整
    • 语言自然流畅
    • 适合小红书阅读习惯
  1. Use WebFetch to extract webpage content
  2. Extract key information: title, body, image URLs
  3. Summarize content appropriately, ensuring:
    • Complete key information
    • Natural and fluent language
    • Suitable for Xiaohongshu reading habits

图片提取失败处理

Image Extraction Failure Handling

如果从网页中提取不到图片URL,或图片URL无法访问,必须
  1. 告知用户图片提取失败
  2. 提供原网页链接,请用户手动访问
  3. 指导用户:
    • 在浏览器中打开原网页
    • 右键点击想要的图片 → "图片另存为" 或 "复制图片地址"
    • 将保存的图片路径或复制的图片URL提供给我
  4. 等待用户提供图片后再继续发布流程
示例提示语
从网页中未能提取到可用的图片。请手动获取:

1. 打开原文链接:[URL]
2. 找到合适的配图,右键另存为本地,或复制图片地址
3. 将图片路径或URL发给我

拿到图片后我们继续发布。
If no image URLs can be extracted from the webpage, or the image URLs are inaccessible, must:
  1. Inform the user that image extraction failed
  2. Provide the original webpage link and ask the user to access it manually
  3. Guide the user:
    • Open the original webpage in the browser
    • Right-click the desired image → "Save image as" or "Copy image address"
    • Provide the saved image path or copied image URL to me
  4. Wait for the user to provide the image before continuing the publishing process
Sample Prompt:
Failed to extract usable images from the webpage. Please obtain them manually:

1. Open the original link: [URL]
2. Find suitable images, right-click to save locally or copy the image address
3. Send the image path or URL to me

We will continue the publishing process after receiving the image.

Step 3: 内容检查

Step 3: Content Check

标题检查

Title Check

标题长度必须 ≤ 38,计算规则:
  • 中文字符和中文标点(《》、,。等):每个计 2
  • 英文字母/数字/空格/ASCII标点:每个计 1
如果超长,自动生成符合长度要求的新标题,保持语义一致。
Title length must be ≤ 38, calculation rules:
  • Chinese characters and Chinese punctuation (《》、,。etc.): Each counts as 2
  • English letters/numbers/spaces/ASCII punctuation: Each counts as 1
If it exceeds the limit, automatically generate a new title that meets the length requirement while maintaining the same meaning.

正文格式

Body Format

  • 段落之间使用双换行分隔
  • 语言自然,避免机器翻译感
  • 简体中文
  • Use double line breaks between paragraphs
  • Natural language, avoid machine translation feel
  • Simplified Chinese

Step 4: 发布到小红书

Step 4: Publish to Xiaohongshu

完整发布流程参考: references/publish-workflow.md
Refer to the complete publishing workflow: references/publish-workflow.md

4.1 用户确认内容

4.1 User Content Confirmation

通过
AskUserQuestion
向用户展示即将发布的内容(标题、正文、图片),获得明确确认后再继续。
Use
AskUserQuestion
to show the user the upcoming content (title, body, images) and obtain explicit confirmation before proceeding.

4.2 选择发布模式

4.2 Select Publishing Mode

通过
AskUserQuestion
让用户选择发布模式:
  • 无头模式(推荐):后台运行,速度快,无浏览器窗口。发布完成后直接报告结果。
  • 有窗口模式:显示浏览器窗口,可以预览内容。需要用户确认后再点击发布。
AskUserQuestion 示例:
问题:选择发布模式
选项:
  - 无头模式(推荐):后台快速发布,无需预览
  - 有窗口模式:显示浏览器,可预览确认
Use
AskUserQuestion
to let the user select the publishing mode:
  • Headless Mode (Recommended): Runs in the background, fast, no browser window. Report results directly after publishing is completed.
  • Windowed Mode: Displays the browser window, allows content preview. Requires user confirmation before clicking publish.
AskUserQuestion Example:
Question: Select Publishing Mode
Options:
  - Headless Mode (Recommended): Fast background publishing, no preview needed
  - Windowed Mode: Displays browser, allows preview and confirmation

4.3 写入临时文件

4.3 Write to Temporary File

将标题和正文写入临时 UTF-8 文本文件。不要在
python -c
中内联中文文本。
Write the title and body to a temporary UTF-8 text file. Do not inline Chinese text in
python -c
.

4.4 运行发布(根据模式分流)

4.4 Execute Publishing (Branch by Mode)

A. 上传图文模式(默认)

A. Image-Text Upload Mode (Default)

根据用户选择的模式执行发布脚本:
无头模式(添加
--headless
参数):
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\publish_pipeline.py" --headless --title-file title.txt --content-file content.txt --image-urls "URL1" "URL2"
有窗口模式(不添加
--headless
):
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\publish_pipeline.py" --title-file title.txt --content-file content.txt --image-urls "URL1" "URL2"
其他参数
bash
undefined
Execute the publishing script according to the user-selected mode:
Headless Mode (add
--headless
parameter):
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\publish_pipeline.py" --headless --title-file title.txt --content-file content.txt --image-urls "URL1" "URL2"
Windowed Mode (do not add
--headless
):
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\publish_pipeline.py" --title-file title.txt --content-file content.txt --image-urls "URL1" "URL2"
Other Parameters:
bash
undefined

发布到指定账号

Publish to specified account

python ... --account myaccount ...
python ... --account myaccount ...

使用本地图片

Use local images

python ... --images "C:\path\to\image.jpg"

处理输出:
- `NOT_LOGGED_IN` (exit code 1) → 脚本自动切换到有窗口模式,提示用户扫码登录,确认后重新运行
- `READY_TO_PUBLISH` (exit code 0) → 根据模式进入下一步
- Exit code 2 → 报告错误
python ... --images "C:\path\to\image.jpg"

Process Output:
- `NOT_LOGGED_IN` (exit code 1) → The script automatically switches to Windowed Mode, prompts the user to scan the code to log in, and re-runs after confirmation
- `READY_TO_PUBLISH` (exit code 0) → Proceed to the next step according to the mode
- Exit code 2 → Report error

B. 写长文模式

B. Long Article Mode

Step B.1 — 填写长文内容 + 一键排版:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" long-article --title-file title.txt --content-file content.txt
可选
--images img1.jpg img2.jpg
插入图片到编辑器中。
输出中包含
TEMPLATES: [...]
JSON 数组,为可用的排版模板名称列表。
Step B.2 — 让用户选择模板:
使用
AskUserQuestion
将模板名称作为选项展示给用户选择(从 TEMPLATES 输出中解析)。
Step B.3 — 选择模板:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" select-template --name "用户选择的模板名"
Step B.4 — 点击下一步并填写发布页正文描述:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" click-next-step --content-file content.txt
注意:发布页有独立的正文描述编辑器,必须通过
--content
--content-file
传入内容填写。 如果正文超过 1000 字,应压缩到 800 字左右再填入,保持语义不变。
Step B.5 — 用户预览确认并发布: 进入下方 4.5 步骤。
Step B.1 — Fill Long Article Content + One-Click Typesetting:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" long-article --title-file title.txt --content-file content.txt
Optional
--images img1.jpg img2.jpg
to insert images into the editor.
The output contains a
TEMPLATES: [...]
JSON array, which is the list of available typesetting template names.
Step B.2 — Let User Select Template:
Use
AskUserQuestion
to display the template names as options for the user to select (parsed from the TEMPLATES output).
Step B.3 — Select Template:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" select-template --name "User-selected Template Name"
Step B.4 — Click Next and Fill Body Description on Publishing Page:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" click-next-step --content-file content.txt
Note: The publishing page has an independent body description editor, which must be filled by passing content via
--content
or
--content-file
. If the body exceeds 1000 words, it should be compressed to around 800 words while maintaining the original meaning before filling in.
Step B.5 — User Preview Confirmation and Publishing: Proceed to Step 4.5 below.

4.5 用户预览确认(仅有窗口模式 / 长文模式)

4.5 User Preview Confirmation (Windowed Mode / Long Article Mode Only)

仅当用户选择有窗口模式或使用长文模式时,使用
AskUserQuestion
请用户在浏览器中检查预览,确认后再发布。
无头模式的图文发布跳过此步骤,直接进入 4.6。
Only when the user selects Windowed Mode or uses Long Article Mode, use
AskUserQuestion
to ask the user to check the preview in the browser and confirm before publishing.
Skip this step for headless mode image-text publishing, directly proceed to 4.6.

4.6 点击发布

4.6 Click Publish

点击发布按钮:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" click-publish
Click the publish button:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" click-publish

4.7 报告结果

4.7 Report Results

根据命令输出告知用户发布是否成功。
Inform the user whether the publishing was successful based on the command output.

重要提示

Important Notes

  • 绝不自动发布 - 必须获得用户确认
  • 图片要求 - 上传图文模式必须有图片;写长文模式图片可选
  • 长文模式 - 必须让用户选择模板,不要自动选择
  • 正文描述 - 长文模式的发布页有独立正文描述框,超过 1000 字需压缩到 800 字左右
  • 无头模式:使用
    --headless
    参数自动化发布。如需登录,脚本自动切换到有窗口模式
  • 如果页面结构变化导致选择器失效,参考
    references/publish-workflow.md
    更新
  • Never publish automatically - Must obtain explicit user confirmation
  • Image Requirements - Image-Text Upload Mode must have images; Long Article Mode images are optional
  • Long Article Mode - Must let the user select a template, do not select automatically
  • Body Description - The publishing page in Long Article Mode has an independent body description box; if it exceeds 1000 words, compress it to around 800 words
  • Headless Mode: Use the
    --headless
    parameter for automated publishing. If login is required, the script automatically switches to Windowed Mode
  • If page structure changes cause selectors to fail, refer to
    references/publish-workflow.md
    for updates

账号管理

Account Management

系统支持多个小红书账号,每个账号有独立的 Chrome profile。
The system supports multiple Xiaohongshu accounts, each with an independent Chrome profile.

列出账号

List Accounts

bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" list-accounts
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" list-accounts

添加账号

Add Account

bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" add-account myaccount --alias "我的账号"
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" add-account myaccount --alias "My Account"

登录

Login

bash
undefined
bash
undefined

默认账号

Default account

python "C:\Users\admin\AI.claude\skills\post-to-xhs\scripts\cdp_publish.py" login
python "C:\Users\admin\AI.claude\skills\post-to-xhs\scripts\cdp_publish.py" login

指定账号

Specified account

python "C:\Users\admin\AI.claude\skills\post-to-xhs\scripts\cdp_publish.py" --account myaccount login
undefined
python "C:\Users\admin\AI.claude\skills\post-to-xhs\scripts\cdp_publish.py" --account myaccount login
undefined

切换账号

Switch Account

bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" switch-account
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" --account otheraccount switch-account
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" switch-account
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" --account otheraccount switch-account

设置默认账号

Set Default Account

bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" set-default-account myaccount
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" set-default-account myaccount