RedBookSkills
将图文/视频内容自动发布到小红书(XHS),并支持登录检查、内容检索与互动操作。 适用场景:发布图文、发布视频、仅启动测试浏览器、获取登录二维码、首页推荐抓取、搜索笔记、评论互动、抓取内容数据。
Safety scan
A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.
Check it deeper on your machine
It has changed since its scan on 11 Nov 2026.
As a Claude Code plugin, install it and then ask Claude Code:
/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/white0dew/xiaohongshuskills with scanskillsafety
Or from a terminal, clone it and run it:
git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/white0dew/xiaohongshuskills'
It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.
Badge for your README
Markdown
[](/listings/white0dew--xiaohongshuskills)HTML
<a href="/listings/white0dew--xiaohongshuskills"><img src="/api/listings/white0dew--xiaohongshuskills/badge.svg" alt="findsafeskills safety rating" /></a>Install
Install instructions from the README
As written by the repo's author. findsafeskills has not verified these steps.
环境要求
- Python 3.10+ - Google Chrome 浏览器 - Windows 操作系统(目前仅测试 Windows)
安装依赖
pip install -r requirements.txt
What was scanned
The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.
SKILL.md · Manifest · 316 lines
View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)
This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.
- ---
- name: RedBookSkills
- description: |
- 将图文/视频内容自动发布到小红书(XHS),并支持登录检查、内容检索与互动操作。
- 适用场景:发布图文、发布视频、仅启动测试浏览器、获取登录二维码、首页推荐抓取、搜索笔记、评论互动、抓取内容数据。
- metadata:
- trigger: 发布内容到小红书
- source: Angiin/Post-to-xhs
- ---
- # Post-to-xhs
- 你是“小红书发布助手”。目标是在用户确认后,调用本 Skill 的脚本完成发布或互动操作。
- ## 风险提示(重要)
- **使用本 Skill 进行小红书自动化,存在被平台风控、限流、封号或封禁账号的风险。**
- 默认提醒用户优先使用测试号、小流量运行,并对最终内容进行人工复核。使用者需自行评估并承担相关风险。
- ## 输入判断
- 优先按以下顺序判断:
- 1. 用户明确要求"测试浏览器 / 启动浏览器 / 检查登录 / 获取登录二维码 / 只打开不发布":进入测试浏览器流程。
- 2. 用户要求“首页推荐 / 搜索笔记 / 找内容 / 查看某篇笔记详情 / 查看内容数据表 / 给帖子评论 / 回复评论 / 点赞收藏互动 / 查看用户主页 / 查看评论和@通知”:进入内容检索与互动流程(`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. 用户已提供 `标题 + 正文 + 视频(本地路径或 URL)`:直接进入视频发布流程。
- 4. 用户已提供 `标题 + 正文 + 图片(本地路径或 URL)`:直接进入图文发布流程。
- 5. 用户只提供网页 URL:先提取网页内容与图片/视频,再给出可发布草稿,等待用户确认。
- 6. 信息不全:先补齐缺失信息,不要直接发布。
- ## 必做约束
- - 发布前必须让用户确认最终标题、正文和图片/视频。
- - 图文发布时,没有图片不得发布(小红书发图文必须有图片)。
- - 视频发布时,没有视频不得发布。图片和视频不可混合使用(二选一)。
- - 默认使用无头模式;若检测到未登录,切换有窗口模式登录。
- - 标题长度不超过 38(中文/中文标点按 2,英文数字按 1)。
- - 用户要求"仅测试浏览器"时,不得触发发布命令。
- - 如使用文件路径,优先使用绝对路径;若用户给的是相对路径,先转换为绝对路径再执行命令。
- - 若发布页结构异常,优先检查 `scripts/cdp_publish.py` 里的 `SELECTORS`、多图上传等待、正文编辑器与发布按钮点击逻辑;这些是最容易被小红书网页改版影响的区域。
- ## 测试浏览器流程(不发布)
- 1. 启动 post-to-xhs 专用 Chrome(默认有窗口模式,便于人工观察)。
- 2. 如用户要求静默运行,再使用无头模式。
- 3. 可选:执行登录状态检查并回传结果。
- 4. 结束后如用户要求,关闭测试浏览器实例。
- ## 图文发布流程
- 1. 准备输入(标题、正文、图片 URL 或本地图片)。
- 2. 如需文件输入,先写入 `title.txt`、`content.txt`。
- 3. 执行发布命令(默认无头)。
- 4. 回传执行结果(成功/失败 + 关键信息)。
- ## 视频发布流程
- 1. 准备输入(标题、正文、视频文件路径或 URL)。
- 2. 如需文件输入,先写入 `title.txt`、`content.txt`。
- 3. 执行视频发布命令(默认无头)。视频上传后需等待处理完成。
- 4. 回传执行结果(成功/失败 + 关键信息)。
- ## 内容检索与互动流程(搜索/详情/评论/内容数据)
- 1. 先检查小红书主页登录状态(`XHS_HOME_URL`,非创作者中心)。
- 2. 若用户需要首页推荐流,执行 `list-feeds` 获取首页推荐笔记列表。
- 3. 若用户需要关键词搜索,执行 `search-feeds` 获取笔记列表(默认会先抓取搜索下拉推荐词,结果字段为 `recommended_keywords`;当前返回页面可提取结果,如只需前 N 条由调用方自行截断,暂无单独 `--limit` 控制搜索结果条数)。
- 4. 若用户需要详情,从搜索结果中取 `id` + `xsecToken` 再执行 `get-feed-detail`;如用户明确要更多评论,可加 `--load-all-comments` 等参数。
- 5. 若用户需要发表评论,执行 `post-comment-to-feed`(一级评论;必填 `feed_id` / `xsec_token` / `content`)。
- 6. 若用户需要回复某条评论,执行 `respond-comment`(可用 `comment_id` / `comment_author` / `comment_snippet` 定位目标评论)。
- 7. 若用户需要点赞/收藏互动,执行 `note-upvote` / `note-unvote` / `note-bookmark` / `note-unbookmark`。
- 8. 若用户需要用户主页信息,执行 `profile-snapshot` 或 `notes-from-profile`。
- 9. 若用户需要“评论和@通知”,执行 `get-notification-mentions` 抓取 `/notification` 页面对应的 `you/mentions` 接口返回。
- 10. 若用户需要“笔记基础信息表”,执行 `content-data` 获取曝光/观看/点赞等指标。
- 11. 回传结构化结果(数量、核心字段、链接)。
- ## 常用命令
- ### 参数顺序提醒(`cdp_publish.py` / `publish_pipeline.py`)
- 请严格按下面顺序写命令,避免 `unrecognized arguments`:
- - 全局参数放在子命令前:`--host --port --headless --account --timing-jitter --reuse-existing-tab`
- - 子命令参数放在子命令后:如 `search-feeds` 的 `--keyword --sort-by --note-type`
- - 常见可选全局参数:`--host 10.0.0.12 --port 9222 --reuse-existing-tab --account NAME`
- 示例(正确):
- ```bash
- python scripts/cdp_publish.py --reuse-existing-tab search-feeds --keyword "春招" --sort-by 最新 --note-type 图文
- ```
- ### 0) 启动 / 测试浏览器(不发布)
- 默认 CDP 地址为 `127.0.0.1:9222`;可按需叠加 `--host` / `--port` 指向远程 Chrome。
- ```bash
- # 启动测试浏览器(有窗口,推荐)
- 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) 首次登录 / 重新登录
- ```bash
- # 本地 Chrome 登录
- python scripts/cdp_publish.py login
- # 远程 CDP 登录(不会自动重启远程 Chrome)
- python scripts/cdp_publish.py --host 10.0.0.12 --port 9222 login
- ```
- ### 1) 准备 title.txt / content.txt
- 若用户给的是标题和正文,可先写入临时文件再执行命令:
- ```bash
- printf '%s\n' '这里是标题' > /abs/path/title.txt
- printf '%s\n' '这里是正文' > /abs/path/content.txt
- ```
- ### 2) 无头发布 or 有头预览 —— 使用图片 URL 发布
- ```bash
- # 默认推荐:无头自动发布
- 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"
- ```
- 说明:当 `--host` 不是 `127.0.0.1/localhost` 时,脚本会跳过本地 `chrome_launcher.py` 的自动启动/重启逻辑。
- 说明:`publish_pipeline.py` 默认自动点击发布;如需停留在发布页人工确认,请加 `--preview`。
- ### 3) 无头发布 or 有头预览 —— 使用本地图片发布
- ```bash
- # 本地图片发布
- 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
- ```
- 说明:当控制端在 WSL 运行,且传入 Windows/UNC 路径(如 `\\wsl.localhost\...`)时,可加 `--skip-file-check`,避免 Linux 侧 `os.path.isfile()` 误判不存在。
- 说明:脚本会自动识别 `C:\...`、`\\wsl.localhost\...` 等 Windows/UNC 路径,并在传给 `DOM.setFileInputFiles` 时保留原始路径形态。
- 说明:若需要强制保留原始路径,也可显式加 `--preserve-upload-paths`。
- ### 3.5) 视频发布(本地视频文件 / 视频 URL)
- ```bash
- # 本地视频文件
- 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) 多账号发布 / 切换
- ```bash
- 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) 搜索内容 / 获取笔记详情
- ```bash
- # 首页推荐笔记
- 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
- ```
- 说明:`list-feeds` 返回首页推荐 feed 列表。
- 说明:`search-feeds` 输出中包含 `recommended_keywords_count` 与 `recommended_keywords`,表示回车前搜索框下拉推荐词。
- 说明:`search-feeds` 返回当前页面可提取到的结果,不提供单独的 `--limit` 条数控制;若只需前 N 条,请在调用方截断返回列表。
- 说明:`get-feed-detail --load-all-comments` 会先滚动评论区,并可选点击“更多回复”后再提取详情,同时额外返回 `comment_loading`。
- 说明:`check-login` 与主页登录检查默认启用本地缓存(12h,仅缓存“已登录”),到期后自动重新网页校验。
- ### 6) 给笔记发表评论(一级评论)
- ```bash
- # 直接传评论文本
- 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) 获取内容数据表(content_data)
- ```bash
- # 获取笔记基础信息表(曝光/观看/封面点击率/点赞/评论/收藏/涨粉/分享/人均观看时长/弹幕)
- 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) 获取评论和@通知(notification mentions)
- ```bash
- # 抓取 /notification 页面触发的 you/mentions 接口数据
- python scripts/cdp_publish.py get-notification-mentions
- # 下划线别名
- python scripts/cdp_publish.py get_notification_mentions
- ```
- ### 9) 评论回复 / 点赞收藏 / 用户主页信息
- ```bash
- # 回复评论(支持按评论 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
- ```
- 补充:更完整的背景说明、安装说明与面向人工阅读的示例可参考 `README.md`,但本文件中的命令样例应优先作为 agent 执行基线。
- ## 失败处理
- - 登录失败:提示用户重新扫码登录并重试;若用户需要远程展示二维码,可改用 `get-login-qrcode`。
- - 图片/视频下载失败:提示更换 URL 或改用本地文件。
- - 本地路径不可用:优先改用绝对路径;若为 WSL/远程 CDP 的 Windows/UNC 路径,可先尝试 `--skip-file-check`,必要时再加 `--preserve-upload-paths`。
- - 评论/回复目标未定位成功:提示补充 `comment_id`,或改用 `comment_author` / `comment_snippet` 再试。
- - 页面选择器失效:提示检查 `scripts/cdp_publish.py` 中选择器并更新。
README.md · README · 426 lines
View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)
This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.
- # RedBookSkills
- ## 赞助商
- <a href="https://go.apimart.ai/gh-xiaohongshuskills"><img src="assets/apimart-banner.png" alt="APIMart:AI 图片与视频生成 API 平台" width="480" /></a>
- 感谢 APIMart 赞助了本项目!APIMart 是专注 AI 图片/视频生成的低价 API 平台,GPT-Image-2 低至 $0.006/张,1 美元可出图 160+ 张。图片、视频一套异步 API 通吃,提交任务拿 ID、回调取结果,跑批万张不超时、换模型不改代码。按量付费、无月费,通过此[注册链接](https://go.apimart.ai/gh-xiaohongshuskills)注册即可开用。
- 自动发布内容到小红书(Xiaohongshu/RED)的命令行工具,也支持仅启动测试浏览器(不发布)。
- 通过 Chrome DevTools Protocol (CDP) 实现自动化发布,支持图文发布、视频发布、多账号管理、无头模式运行、自动搜索素材与内容数据抓取等功能。
- ## 风险提示(重要)
- **使用本项目进行小红书自动化,存在被平台风控、限流、封号或封禁账号的风险。**
- 建议仅先在测试号上验证,控制发布频率和流量规模,并对最终发布内容进行人工复核。使用者需自行评估并承担由此带来的账号、内容、流量及其他相关风险。
- ## 功能特性
- - **自动化发布**:自动填写标题、正文,支持上传图片或视频
- - **创作者中心兼容修复**:适配 2026 年 2-3 月发布页 DOM 变动(发布按钮、定时开关、日期输入、多图上传等待、正文编辑器)
- - **话题标签自动写入**:识别正文最后一行 `#标签`,然后逐渐写入
- - **多账号支持**:支持管理多个小红书账号,各账号 Cookie 隔离
- - **无头模式**:支持后台运行,无需显示浏览器窗口
- - **远程 CDP 支持**:可通过 `--host` / `--port` 连接远程 Chrome 调试端口
- - **图片下载**:支持从 URL 自动下载图片,自动添加 Referer 绕过防盗链
- - **登录检测**:自动检测登录状态,未登录时自动切换到有窗口模式扫码
- - **登录二维码导出**:支持返回登录二维码 Base64 图片,便于远程前端展示扫码
- - **登录状态缓存**:`check_login/check_home_login` 默认本地缓存 12 小时,减少重复跳转校验
- - **首页推荐流抓取**:支持抓取首页推荐 feed 列表
- - **内容检索与详情读取**:支持搜索笔记并获取指定笔记详情(含评论数据),详情可选滚动加载更多评论/回复
- - **笔记评论**:支持按 `feed_id + xsec_token` 对指定笔记发表一级评论
- - **评论回复**:支持按评论定位条件(评论 ID / 作者 / 文本片段)回复指定评论
- - **互动动作控制**:支持对指定笔记执行点赞/取消点赞、收藏/取消收藏
- - **用户页信息提取**:支持抓取用户主页快照与主页笔记列表
- - **通知评论抓取**:支持在 `/notification` 页面抓取 `you/mentions` 接口返回
- - **内容数据看板抓取**:支持抓取“笔记基础信息”表(曝光/观看/点赞等)并导出 CSV
- ## 安装
- ### 环境要求
- - Python 3.10+
- - Google Chrome 浏览器
- - Windows 操作系统(目前仅测试 Windows)
- ### 安装依赖
- ```bash
- pip install -r requirements.txt
- ```
- ## 快速开始
- ### 1. 首次登录
- ```bash
- python scripts/cdp_publish.py login
- ```
- 在弹出的 Chrome 窗口中扫码登录小红书。
- 说明:当前发布链路已按 2026 年 2-3 月的小红书创作者中心改版调整过选择器与等待策略;如果后续再次改版,优先检查 `scripts/cdp_publish.py` 中的 `SELECTORS`、多图上传等待和发布按钮点击逻辑。
- ### 2. 启动/测试浏览器(不发布)
- ```bash
- # 启动测试浏览器(有窗口,推荐)
- python scripts/chrome_launcher.py
- # 无头启动测试浏览器
- python scripts/chrome_launcher.py --headless
- # 检查当前登录状态
- python scripts/cdp_publish.py check-login
- # 获取登录二维码(返回 Base64,可供远程前端直接展示)
- python scripts/cdp_publish.py get-login-qrcode
- # 可选:优先复用已有标签页(减少有窗口模式下切到前台)
- python scripts/cdp_publish.py check-login --reuse-existing-tab
- # 连接远程 CDP(Chrome 在另一台机器)
- python scripts/cdp_publish.py --host 10.0.0.12 --port 9222 check-login
- # 重启测试浏览器
- python scripts/chrome_launcher.py --restart
- # 关闭测试浏览器
- python scripts/chrome_launcher.py --kill
- ```
- ### 3. 发布内容
- ```bash
- # 无头模式(推荐,默认自动发布)
- python scripts/publish_pipeline.py --headless \
- --title "文章标题" \
- --content "文章正文" \
- --image-urls "https://example.com/image.jpg"
- # 有窗口预览模式(仅填充,不自动点发布)
- python scripts/publish_pipeline.py \
- --preview \
- --title "文章标题" \
- --content "文章正文" \
- --image-urls "https://example.com/image.jpg"
- # 可选:优先复用已有标签页(减少有窗口模式下切到前台)
- python scripts/publish_pipeline.py --reuse-existing-tab \
- --title "文章标题" \
- --content "文章正文" \
- --image-urls "https://example.com/image.jpg"
- # 连接远程 CDP 并发布(远程 Chrome 需已开启调试端口)
- python scripts/publish_pipeline.py --host 10.0.0.12 --port 9222 \
- --title "文章标题" \
- --content "文章正文" \
- --image-urls "https://example.com/image.jpg"
- # 从文件读取内容
- python scripts/publish_pipeline.py --headless \
- --title-file title.txt \
- --content-file content.txt \
- --image-urls "https://example.com/image.jpg"
- # 正文最后一行可放话题标签(最多 10 个)
- # 例如 content.txt 最后一行:
- # #春招 #26届 #校招 #求职 #找工作
- # 使用本地图片
- python scripts/publish_pipeline.py --headless \
- --title "文章标题" \
- --content "文章正文" \
- --images "C:\path\to\image.jpg"
- # 使用本地视频
- python scripts/publish_pipeline.py --headless \
- --title "视频标题" \
- --content "视频正文" \
- --video "C:\path\to\video.mp4"
- # 使用视频 URL
- python scripts/publish_pipeline.py --headless \
- --title "视频标题" \
- --content "视频正文" \
- --video-url "https://example.com/video.mp4"
- # WSL/远程 CDP + Windows/UNC 路径可跳过本地文件预校验
- python scripts/publish_pipeline.py --headless \
- --title "文章标题" \
- --content "文章正文" \
- --images "\\wsl.localhost\Ubuntu\home\user\image.jpg" \
- --skip-file-check
- ```
- ### 4. 多账号管理
- ```bash
- # 列出所有账号
- python scripts/cdp_publish.py list-accounts
- # 添加新账号
- python scripts/cdp_publish.py add-account myaccount --alias "我的账号"
- # 登录指定账号
- python scripts/cdp_publish.py --account myaccount login
- # 使用指定账号发布
- python scripts/publish_pipeline.py --account myaccount --headless \
- --title "标题" --content "正文" --image-urls "URL"
- # 设置默认账号
- python scripts/cdp_publish.py set-default-account myaccount
- # 切换账号(清除当前登录,重新扫码)
- python scripts/cdp_publish.py switch-account
- ```
- ### 5. 搜索内容、查看笔记详情与互动操作
- ```bash
- # 首页推荐列表
- python scripts/cdp_publish.py list-feeds
- # 搜索笔记(可选筛选)
- python scripts/cdp_publish.py search-feeds --keyword "春招"
- python scripts/cdp_publish.py search-feeds --keyword "春招" --sort-by 最新 --note-type 图文
- # 获取笔记详情(feed_id 与 xsec_token 可从搜索结果中获取)
- python scripts/cdp_publish.py get-feed-detail \
- --feed-id 67abc1234def567890123456 \
- --xsec-token YOUR_XSEC_TOKEN
- # 可选:滚动加载更多一级评论,并尝试展开二级回复
- python scripts/cdp_publish.py get-feed-detail \
- --feed-id 67abc1234def567890123456 \
- --xsec-token YOUR_XSEC_TOKEN \
- --load-all-comments \
- --limit 20 \
- --click-more-replies \
- --reply-limit 10 \
- --scroll-speed normal
- # 给笔记发表评论(一级评论)
- python scripts/cdp_publish.py post-comment-to-feed \
- --feed-id 67abc1234def567890123456 \
- --xsec-token YOUR_XSEC_TOKEN \
- --content "写得很实用,感谢分享!"
- # 回复指定评论(可按评论ID / 作者 / 文本片段定位)
- python scripts/cdp_publish.py respond-comment \
- --feed-id 67abc1234def567890123456 \
- --xsec-token YOUR_XSEC_TOKEN \
- --comment-id COMMENT_ID \
- --content "感谢你的反馈~"
- # 点赞 / 取消点赞
- python scripts/cdp_publish.py note-upvote --feed-id 67abc1234def567890123456 --xsec-token YOUR_XSEC_TOKEN
- python scripts/cdp_publish.py note-unvote --feed-id 67abc1234def567890123456 --xsec-token YOUR_XSEC_TOKEN
- # 收藏 / 取消收藏
- python scripts/cdp_publish.py note-bookmark --feed-id 67abc1234def567890123456 --xsec-token YOUR_XSEC_TOKEN
- python scripts/cdp_publish.py note-unbookmark --feed-id 67abc1234def567890123456 --xsec-token YOUR_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
- # 抓取“评论和@”通知接口(you/mentions)
- python scripts/cdp_publish.py get-notification-mentions
- ```
- 说明:`list-feeds` 返回首页推荐 feed 列表;`search-feeds` 会先在搜索框输入关键词,抓取下拉推荐词(`recommended_keywords`),再回车拉取 feed 列表。
- 说明:`search-feeds` 当前返回的是页面上可提取到的结果集合;如果调用方只需要前 N 条,可以自行截断结果。当前没有单独的 `--limit` 参数用于控制搜索结果条数。
- 说明:`get-feed-detail --load-all-comments` 会在详情页滚动评论区,并可选点击“更多回复”后再提取 `window.__INITIAL_STATE__`。
- ### 6. 获取内容数据表(content_data)
- ```bash
- # 抓取“笔记基础信息”数据表
- python scripts/cdp_publish.py content-data
- # 下划线别名
- python scripts/cdp_publish.py content_data
- # 导出 CSV
- python scripts/cdp_publish.py content-data --csv-file "/abs/path/content_data.csv"
- ```
- ## 命令参考
- ### 话题标签(publish_pipeline.py)
- - 从正文中提取规则:若“最后一个非空行”全部由 `#标签` 组成,则提取为话题标签并从正文移除。
- - 标签输入策略:逐个输入 `#标签`,等待 `3` 秒,再发送 `Enter` 进行确认。
- - 建议数量:`1-10` 个标签;超过平台限制时请手动精简。
- - 示例(正文最后一行):`#春招 #26届 #校招 #春招规划 #面试`
- ### publish_pipeline.py
- 统一发布入口,一条命令完成全部流程。
- ```bash
- python scripts/publish_pipeline.py [选项]
- 选项:
- --title TEXT 文章标题
- --title-file FILE 从文件读取标题
- --content TEXT 文章正文
- --content-file FILE 从文件读取正文
- --image-urls URL... 图片 URL 列表
- --images FILE... 本地图片文件列表
- --video FILE 本地视频文件
- --video-url URL 视频 URL(先下载再上传)
- --skip-file-check 跳过本地媒体文件存在性检查(WSL/远程 CDP/UNC 路径可用)
- --preserve-upload-paths 强制保留原始上传路径,不将反斜杠转换为正斜杠
- --host HOST CDP 主机地址(默认 127.0.0.1)
- --port PORT CDP 端口(默认 9222)
- --headless 无头模式(无浏览器窗口)
- --reuse-existing-tab 优先复用已有标签页(默认关闭)
- --account NAME 指定账号
- --auto-publish 兼容参数:默认已自动发布(可省略)
- --preview 预览模式:仅填充内容,不点击发布
- ```
- 说明:启用 `--reuse-existing-tab` 后,发布流程仍会自动导航到发布页,因此会刷新到目标页面再继续执行。
- 说明:当 `--host` 非 `127.0.0.1/localhost` 时为远程模式,会跳过本地 `chrome_launcher.py` 的自动启动/重启逻辑,请确保远程 CDP 地址可达。
- 说明:当控制端运行在 WSL、但媒体路径使用 Windows/UNC(如 `\\wsl.localhost\...`)时,可加 `--skip-file-check` 跳过 Linux 侧 `isfile` 预校验。
- 说明:脚本现在会自动识别 `C:\...`、`\\wsl.localhost\...` 等 Windows/UNC 路径,并在传给 `DOM.setFileInputFiles` 时保留原始形态。
- 说明:若仍想强制关闭路径改写,可显式加 `--preserve-upload-paths`。
- 说明:`publish_pipeline.py` 默认会自动点击发布;如需人工确认,请显式加 `--preview`。
- ### cdp_publish.py
- 底层发布控制,支持分步操作。
- ```bash
- # 检查登录状态
- python scripts/cdp_publish.py check-login
- python scripts/cdp_publish.py check-login --reuse-existing-tab
- python scripts/cdp_publish.py --host 10.0.0.12 --port 9222 check-login
- # 填写表单(不发布)
- python scripts/cdp_publish.py fill --title "标题" --content "正文" --images img.jpg
- python scripts/cdp_publish.py fill --title "标题" --content "正文" --images img.jpg --reuse-existing-tab
- python scripts/cdp_publish.py --host 10.0.0.12 --port 9222 fill --title "标题" --content "正文" --images img.jpg
- # 点击发布按钮
- python scripts/cdp_publish.py click-publish
- # 获取登录二维码(支持下划线别名:get_login_qrcode)
- python scripts/cdp_publish.py get-login-qrcode
- # 首页推荐列表(支持下划线别名:list_feeds)
- python scripts/cdp_publish.py list-feeds
- # 搜索笔记(支持下划线别名:search_feeds)
- python scripts/cdp_publish.py search-feeds --keyword "春招"
- python scripts/cdp_publish.py search-feeds --keyword "春招" --sort-by 最新 --note-type 图文
- # 获取笔记详情(支持下划线别名:get_feed_detail)
- python scripts/cdp_publish.py get-feed-detail --feed-id FEED_ID --xsec-token XSEC_TOKEN
- python scripts/cdp_publish.py get-feed-detail --feed-id FEED_ID --xsec-token XSEC_TOKEN --load-all-comments --limit 20 --click-more-replies --reply-limit 10 --scroll-speed normal
- # 发表评论(支持下划线别名:post_comment_to_feed)
- python scripts/cdp_publish.py post-comment-to-feed --feed-id FEED_ID --xsec-token XSEC_TOKEN --content "评论内容"
- # 回复评论(支持下划线别名:respond_comment)
- python scripts/cdp_publish.py respond-comment --feed-id FEED_ID --xsec-token XSEC_TOKEN --content "回复内容" [--comment-id COMMENT_ID]
- # 点赞/取消点赞(支持下划线别名:note_upvote / note_unvote)
- python scripts/cdp_publish.py note-upvote --feed-id FEED_ID --xsec-token XSEC_TOKEN
- python scripts/cdp_publish.py note-unvote --feed-id FEED_ID --xsec-token XSEC_TOKEN
- # 收藏/取消收藏(支持下划线别名:note_bookmark / note_unbookmark)
- python scripts/cdp_publish.py note-bookmark --feed-id FEED_ID --xsec-token XSEC_TOKEN
- python scripts/cdp_publish.py note-unbookmark --feed-id FEED_ID --xsec-token XSEC_TOKEN
- # 用户主页快照/主页笔记(支持下划线别名:profile_snapshot / notes_from_profile)
- python scripts/cdp_publish.py profile-snapshot --profile-url "https://www.xiaohongshu.com/user/profile/USER_ID"
- python scripts/cdp_publish.py notes-from-profile --user-id USER_ID --limit 20 --max-scrolls 3
- # 抓取通知评论接口(支持下划线别名:get_notification_mentions)
- python scripts/cdp_publish.py get-notification-mentions
- # 获取内容数据表(支持下划线别名:content_data)
- python scripts/cdp_publish.py content-data
- python scripts/cdp_publish.py content-data --csv-file "/abs/path/content_data.csv"
- # 账号管理
- python scripts/cdp_publish.py login
- python scripts/cdp_publish.py list-accounts
- python scripts/cdp_publish.py add-account NAME [--alias ALIAS]
- python scripts/cdp_publish.py remove-account NAME [--delete-profile]
- python scripts/cdp_publish.py set-default-account NAME
- python scripts/cdp_publish.py switch-account
- ```
- 说明:`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` 会校验 `xiaohongshu.com` 主页登录态(非创作者中心登录态)。
- 说明:登录态检查默认启用本地缓存(12 小时,仅缓存“已登录”结果),到期后自动重新走网页校验。
- 说明:`get-login-qrcode` 返回 `qrcode_base64` / `qrcode_data_url`,便于远程前端直接展示扫码。
- 说明:`search-feeds` 输出新增 `recommended_keywords_count` 与 `recommended_keywords` 字段,表示输入关键词后回车前的下拉推荐词。
- 说明:`search-feeds` 返回当前页面可提取到的结果,不提供单独的 `--limit` 条数控制;若只需前 N 条,请在调用方截断返回列表。
- 说明:`get-feed-detail --load-all-comments` 额外返回 `comment_loading`,用于说明评论滚动加载结果。
- 说明:`content-data` 会校验创作者中心登录态,并抓取 `statistics/data-analysis` 页面中的笔记基础信息表。
- ### chrome_launcher.py
- Chrome 浏览器管理。
- ```bash
- # 启动 Chrome
- python scripts/chrome_launcher.py
- python scripts/chrome_launcher.py --headless
- # 重启 Chrome
- python scripts/chrome_launcher.py --restart
- # 关闭 Chrome
- python scripts/chrome_launcher.py --kill
- ```
- ## 支持各种 Skill 工具
- 本项目可作为 Claude Code、OpenCode 等支持 Skill 的工具使用,只需将项目复制到 `.claude/skills/post-to-xhs/` 目录,并添加 `SKILL.md` 文件即可。
- 详见 [docs/claude-code-integration.md](docs/claude-code-integration.md)
- ## 注意事项
- 1. **仅供学习研究**:请遵守小红书平台规则,不要用于违规内容发布
- 2. **登录安全**:Cookie 存储在本地 Chrome Profile 中,请勿泄露
- 3. **选择器更新**:如果小红书页面结构变化导致发布失败,需要更新 `cdp_publish.py` 中的选择器
- 4. feed 的图片类型
- - WB_PRV:预览图(preview),通常更轻、更快,适合列表卡片。
- - WB_DFT:默认图(default),通常用于详情展示,质量/尺寸更完整。
- ## RoadMap
- - [x] 支持更多账号管理功能
- - [x] 支持发布功能
- - [x] 增加后台笔记获取功能
- - [x] 支持自动评论
- - [x] 支持素材检索功能
- - [x] 增加更多错误处理机制
- ## 许可证
- MIT License
- ## 联系方式
- 微信号:`whitedewstory`
- <img src="public/whitedew.jpg" alt="微信二维码" width="240" />
- ### 微信群二维码
- 微信群:白露的 Ai+知识圈 1
- <img src="https://png1.aistar.cool/qr/wechat-group.png" alt="微信群二维码" width="240" />
- ## Stars
- [](https://github.com/white0dew/XiaohongshuSkills/stargazers)
- ## 致谢
- 灵感来自:[Post-to-xhs](https://github.com/Angiin/Post-to-xhs)
Ratings and comments
Sign in to rate this skill.
Sign inFree to use. If it’s helped, pass it on.