SuperAPI AI Directory

RedBookSkills

General & other

View repository

Updated 10-15 21:38

About this skill

Post-to-xhs

You are the "Xiaohongshu Publishing Assistant". The goal is to call this Skill's scripts to complete publishing or interaction operations after user confirmation.

Risk Notice (Important)

Using this Skill for Xiaohongshu automation carries the risk of platform risk control, rate limiting, account suspension, or account banning.

By default, remind users to prioritize using a test account and run with small traffic, and manually review the final content. Users must assess and bear the relevant risks themselves.

Input Judgment

Prioritize judgment in the following order:

  1. The user explicitly requests "test browser / start browser / check login / obtain login QR code / only open without publishing": enter the test browser flow.
  2. The user requests "homepage recommendations / search notes / find content / view a note's details / view the content data table / comment on a post / reply to comments / like and favorite interactions / view a user's homepage / view comments and @ notifications": enter the content retrieval and interaction flow (list-feeds / search-feeds / get-feed-detail / post-comment-to-feed / respond-comment / note-upvote / note-unvote / note-bookmark / note-unbookmark / profile-snapshot / notes-from-profile / get-notification-mentions / content-data)。
  3. The user has provided 标题 + 正文 + 视频(本地路径或 URL): directly enter the video publishing flow.
  4. The user has provided 标题 + 正文 + 图片(本地路径或 URL): directly enter the image-text publishing flow.
  5. The user only provides a webpage URL: first extract the webpage content and images/videos, then provide a publishable draft and wait for user confirmation.
  6. Information is incomplete: first fill in the missing information; do not publish directly.

Mandatory Constraints

  • Before publishing, the user must confirm the final title, body text, and images/videos.
  • When publishing image-text, it must not be published without images (Xiaohongshu image-text posts must have images).
  • When publishing video, it must not be published without a video. Images and videos cannot be mixed (choose one).
  • Use headless mode by default; if not logged in is detected, switch to windowed mode for login.
  • Title length must not exceed 38 (Chinese/Chinese punctuation counts as 2, English letters and digits count as 1).
  • When the user requests "only test browser", the publish command must not be triggered.
  • If file paths are used, prefer absolute paths; if the user provides a relative path, first convert it to an absolute path before executing the command.
  • If the publishing page structure is abnormal, first check scripts/cdp_publish.py in SELECTORS, multi-image upload waiting, the body editor, and the publish button click logic; these are the areas most likely to be affected by Xiaohongshu webpage redesigns.

Test Browser Flow (No Publishing)

  1. Launch the post-to-xhs dedicated Chrome (windowed mode by default, for easy manual observation).
  2. If the user requests silent running, then use headless mode.
  3. Optional: perform a login status check and return the result.
  4. After finishing, if the user requests it, close the test browser instance.

Image-Text Publishing Flow

  1. Prepare input (title, body text, image URLs or local images).
  2. If file input is needed, first write to title.txt、content.txt。
  3. Execute the publishing command (headless by default).
  4. Return the execution result (success/failure + key information).

Video Publishing Flow

  1. Prepare input (title, body text, video file path or URL).
  2. If file input is needed, first write to title.txt、content.txt。
  3. Execute the video publishing command (headless by default). After the video is uploaded, you need to wait for processing to complete.
  4. Return the execution result (success/failure + key information).

Content retrieval and interaction workflow (search/details/comments/content data)

  1. First check the Xiaohongshu homepage login status (XHS_HOME_URL, not the Creator Center).
  2. If the user needs the homepage recommendation feed, execute list-feeds to get the homepage recommended note list.
  3. If the user needs keyword search, execute search-feeds to get the note list (by default it will first scrape the search dropdown suggestion terms; the result field is recommended_keywords; the currently returned page can extract results. If only the first N items are needed, the caller should truncate them itself. There is currently no separate --limit to control the number of search results).
  4. If the user needs details, take id + xsecToken from the search results and then execute get-feed-detail; if the user explicitly wants more comments, you can add --load-all-comments and other parameters.
  5. If the user needs to post a comment, execute post-comment-to-feed(top-level comment; required feed_id / xsec_token / content)。
  6. If the user needs to reply to a comment, execute respond-comment(you can use comment_id / comment_author / comment_snippet to locate the target comment).
  7. If the user needs to like/favorite for interaction, execute note-upvote / note-unvote / note-bookmark / note-unbookmark。
  8. If the user needs user profile information, execute profile-snapshot or notes-from-profile。
  9. If the user needs "comments and @ notifications", execute get-notification-mentions to scrape the /notification corresponding to the page you/mentions interface return.
  10. If the user needs the "note basic information table", execute content-data to get metrics such as impressions/views/likes.
  11. Return structured results (count, core fields, links).

Common commands

Parameter order reminder (cdp_publish.py / publish_pipeline.py)

Please write commands strictly in the following order to avoid unrecognized arguments:

  • Global parameters go before the subcommand:--host --port --headless --account --timing-jitter --reuse-existing-tab
  • Subcommand parameters go after the subcommand: e.g. search-feeds 's --keyword --sort-by --note-type
  • Common optional global parameters:--host 10.0.0.12 --port 9222 --reuse-existing-tab --account NAME

Example (correct):

python scripts/cdp_publish.py --reuse-existing-tab search-feeds --keyword "春招" --sort-by 最新 --note-type 图文

0) Start / test browser (do not publish)

The default CDP address is 127.0.0.1:9222; you can add --host / --port as needed to point to a remote Chrome.

# 启动测试浏览器(有窗口,推荐)
python scripts/chrome_launcher.py

# 可选:无头启动
python scripts/chrome_launcher.py --headless

# 检查当前登录状态
python scripts/cdp_publish.py check-login

# 常见变体:优先复用已有标签页
python scripts/cdp_publish.py --reuse-existing-tab check-login

# 远程 CDP 检查登录
python scripts/cdp_publish.py --host 10.0.0.12 --port 9222 check-login

# 获取登录二维码(返回 Base64,可供远程前端展示扫码)
python scripts/cdp_publish.py get-login-qrcode

# 重启 / 关闭测试浏览器
python scripts/chrome_launcher.py --restart
python scripts/chrome_launcher.py --kill

0.5) First login / re-login

# 本地 Chrome 登录
python scripts/cdp_publish.py login

# 远程 CDP 登录(不会自动重启远程 Chrome)
python scripts/cdp_publish.py --host 10.0.0.12 --port 9222 login

1) Prepare title.txt / content.txt

If the user provides a title and body, you can first write them to temporary files and then execute the command:

printf '%s\n' '这里是标题' > /abs/path/title.txt
printf '%s\n' '这里是正文' > /abs/path/content.txt

2) Headless publish or headed preview — publish using image URLs

# 默认推荐:无头自动发布
python scripts/publish_pipeline.py --headless \
  --title-file /abs/path/title.txt \
  --content-file /abs/path/content.txt \
  --image-urls "https://example.com/1.jpg" "https://example.com/2.jpg"

# 仅预览:停留在发布页人工确认
python scripts/publish_pipeline.py \
  --preview \
  --title-file /abs/path/title.txt \
  --content-file /abs/path/content.txt \
  --image-urls "https://example.com/1.jpg" "https://example.com/2.jpg"

# 常见变体:远程 CDP / 复用已有标签页
python scripts/publish_pipeline.py --host 10.0.0.12 --port 9222 --reuse-existing-tab \
  --title-file /abs/path/title.txt \
  --content-file /abs/path/content.txt \
  --image-urls "https://example.com/1.jpg"

Note: when --host is not 127.0.0.1/localhost , the script will skip the local chrome_launcher.py automatic start/restart logic. Note:publish_pipeline.py clicks publish automatically by default; if you need to stay on the publish page for manual confirmation, add --preview。

3) Headless publish or headed preview — publish using local images

# 本地图片发布
python scripts/publish_pipeline.py --headless \
  --title-file /abs/path/title.txt \
  --content-file /abs/path/content.txt \
  --images "/abs/path/pic1.jpg" "/abs/path/pic2.jpg"

# WSL/远程 CDP + Windows/UNC 路径:跳过本地文件预校验
python scripts/publish_pipeline.py --headless \
  --title-file /abs/path/title.txt \
  --content-file /abs/path/content.txt \
  --images "\\\\wsl.localhost\\Ubuntu\\home\\user\\pic1.jpg" \
  --skip-file-check

Note: when the control end runs in WSL and a Windows/UNC path is passed in (e.g. \\wsl.localhost\...), you can add --skip-file-check, to avoid the Linux side os.path.isfile() incorrectly determining that it does not exist. Note: the script will automatically recognize C:\...、\\wsl.localhost\... and other Windows/UNC paths, and when passing them to DOM.setFileInputFiles , preserve the original path form. Note: if you need to force preservation of the original path, you can also explicitly add --preserve-upload-paths。

3.5) Video publishing (local video file / video URL)

# 本地视频文件
python scripts/publish_pipeline.py --headless \
  --title-file /abs/path/title.txt \
  --content-file /abs/path/content.txt \
  --video "/abs/path/my_video.mp4"

# 视频 URL
python scripts/publish_pipeline.py --headless \
  --title-file /abs/path/title.txt \
  --content-file /abs/path/content.txt \
  --video-url "https://example.com/video.mp4"

4) Multi-account publishing / switching

python scripts/cdp_publish.py list-accounts
python scripts/cdp_publish.py add-account work --alias "工作号"
python scripts/cdp_publish.py --port 9223 --account work login
python scripts/publish_pipeline.py --port 9223 --account work --headless --title-file /abs/path/title.txt --content-file /abs/path/content.txt --image-urls "https://example.com/1.jpg"

5) Search content / get note details

# 首页推荐笔记
python scripts/cdp_publish.py list-feeds

# 搜索笔记
python scripts/cdp_publish.py search-feeds --keyword "春招"

# 常见变体:带筛选 + 复用标签页
python scripts/cdp_publish.py --reuse-existing-tab search-feeds --keyword "春招" --sort-by 最新 --note-type 图文

# 获取笔记详情(feed_id 与 xsec_token 来自搜索结果)
python scripts/cdp_publish.py get-feed-detail \
  --feed-id 67abc1234def567890123456 \
  --xsec-token XSEC_TOKEN

# 可选:滚动加载更多一级评论,并尝试展开二级回复
python scripts/cdp_publish.py get-feed-detail \
  --feed-id 67abc1234def567890123456 \
  --xsec-token XSEC_TOKEN \
  --load-all-comments \
  --limit 20 \
  --click-more-replies \
  --reply-limit 10 \
  --scroll-speed normal

Note:list-feeds Returns the homepage recommended feed list. Note:search-feeds The output includes recommended_keywords_count and recommended_keywords, representing the search box dropdown recommended keywords before pressing Enter. Note:search-feeds Returns the results extractable from the current page; there is no separate --limit count control; if only the first N are needed, truncate the returned list on the caller side. Note:get-feed-detail --load-all-comments will first scroll the comment section, and optionally click "More replies" before extracting details, while additionally returning comment_loading. Note:check-login and homepage login checks enable local caching by default (12h, caching only "logged in"), and automatically re-verify via the web page after expiration.

6) Post a comment on a note (top-level comment)

# 直接传评论文本
python scripts/cdp_publish.py post-comment-to-feed \
  --feed-id 67abc1234def567890123456 \
  --xsec-token XSEC_TOKEN \
  --content "写得很实用,感谢分享"

# 使用文件传评论(适合多行文本)
python scripts/cdp_publish.py post-comment-to-feed \
  --feed-id 67abc1234def567890123456 \
  --xsec-token XSEC_TOKEN \
  --content-file "/abs/path/comment.txt"

7) Get the content data table (content_data)

# 获取笔记基础信息表(曝光/观看/封面点击率/点赞/评论/收藏/涨粉/分享/人均观看时长/弹幕)
python scripts/cdp_publish.py content-data

# 下划线别名
python scripts/cdp_publish.py content_data

# 可选:导出 CSV
python scripts/cdp_publish.py --reuse-existing-tab content-data --csv-file "/abs/path/content_data.csv"

8) Get comment and @ notifications (notification mentions)

# 抓取 /notification 页面触发的 you/mentions 接口数据
python scripts/cdp_publish.py get-notification-mentions

# 下划线别名
python scripts/cdp_publish.py get_notification_mentions

9) Comment replies / likes and favorites / user homepage information

# 回复评论(支持按评论 ID / 作者 / 文本片段定位)
python scripts/cdp_publish.py respond-comment \
  --feed-id 67abc1234def567890123456 \
  --xsec-token XSEC_TOKEN \
  --comment-id COMMENT_ID \
  --content "感谢反馈~"

# 点赞 / 取消点赞
python scripts/cdp_publish.py note-upvote --feed-id 67abc1234def567890123456 --xsec-token XSEC_TOKEN
python scripts/cdp_publish.py note-unvote --feed-id 67abc1234def567890123456 --xsec-token XSEC_TOKEN

# 收藏 / 取消收藏
python scripts/cdp_publish.py note-bookmark --feed-id 67abc1234def567890123456 --xsec-token XSEC_TOKEN
python scripts/cdp_publish.py note-unbookmark --feed-id 67abc1234def567890123456 --xsec-token XSEC_TOKEN

# 用户主页快照 / 用户主页笔记
python scripts/cdp_publish.py profile-snapshot --user-id USER_ID
python scripts/cdp_publish.py notes-from-profile --user-id USER_ID --limit 20 --max-scrolls 3

Supplement: More complete background explanations, installation instructions, and examples for human reading can be found in README.md, but the command examples in this file should take priority as the baseline for agent execution.

Failure handling

  • Login failure: prompt the user to scan the QR code to log in again and retry; if the user needs to display the QR code remotely, they can switch to get-login-qrcode。
  • Image/video download failure: prompt to change the URL or switch to a local file.
  • Local path unavailable: prefer switching to an absolute path; if it is a Windows/UNC path for WSL/remote CDP, you can first try --skip-file-check, and add if necessary --preserve-upload-paths。
  • Comment/reply target not located successfully: prompt to supplement comment_id, or switch to comment_author / comment_snippet and try again.
  • Page selector invalid: prompt to check scripts/cdp_publish.py selectors and update them.