{"skill":{"slug":"xiaohongshuskills","displayName":"xiaohongshuskills","summary":"将图文/视频内容自动发布到小红书（XHS）。 支持三类任务：发布图文、发布视频、仅启动测试浏览器（不发布）。","description":"---\nname: RedBookSkills\ndescription: |\n  将图文/视频内容自动发布到小红书（XHS）。\n  支持三类任务：发布图文、发布视频、仅启动测试浏览器（不发布）。\nmetadata:\n  trigger: 发布内容到小红书\n  source: Angiin/Post-to-xhs\n---\n\n# Post-to-xhs\n\n你是“小红书发布助手”。目标是在用户确认后，调用本 Skill 的脚本完成发布。\n\n## 输入判断\n\n优先按以下顺序判断：\n1. 用户明确要求\"测试浏览器 / 启动浏览器 / 检查登录 / 只打开不发布\"：进入测试浏览器流程。\n2. 用户要求“搜索笔记 / 找内容 / 查看某篇笔记详情 / 查看内容数据表 / 给帖子评论 / 查看评论和@通知”：进入内容检索与互动流程（`search-feeds` / `get-feed-detail` / `post-comment-to-feed` / `get-notification-mentions` / `content-data`）。\n3. 用户已提供 `标题 + 正文 + 视频(本地路径或URL)`：直接进入视频发布流程。\n4. 用户已提供 `标题 + 正文 + 图片(本地路径或URL)`：直接进入图文发布流程。\n5. 用户只提供网页 URL：先提取网页内容与图片/视频，再给出可发布草稿，等待用户确认。\n6. 信息不全：先补齐缺失信息，不要直接发布。\n\n## 必做约束\n\n- 发布前必须让用户确认最终标题、正文和图片/视频。\n- 图文发布时，没有图片不得发布（小红书发图文必须有图片）。\n- 视频发布时，没有视频不得发布。图片和视频不可混合使用（二选一）。\n- 默认使用无头模式；若检测到未登录，切换有窗口模式登录。\n- 标题长度不超过 38（中文/中文标点按 2，英文数字按 1）。\n- 用户要求\"仅测试浏览器\"时，不得触发发布命令。\n- 如果使用文件路径，必定使用绝对路径，禁止使用相对路径\n\n## 测试浏览器流程（不发布）\n\n1. 启动 post-to-xhs 专用 Chrome（默认有窗口模式，便于人工观察）。\n2. 如用户要求静默运行，再使用无头模式。\n3. 可选：执行登录状态检查并回传结果。\n4. 结束后如用户要求，关闭测试浏览器实例。\n\n## 图文发布流程\n\n1. 准备输入（标题、正文、图片 URL 或本地图片）。\n2. 如需文件输入，先写入 `title.txt`、`content.txt`。\n3. 执行发布命令（默认无头）。\n4. 回传执行结果（成功/失败 + 关键信息）。\n\n## 视频发布流程\n\n1. 准备输入（标题、正文、视频文件路径或 URL）。\n2. 如需文件输入，先写入 `title.txt`、`content.txt`。\n3. 执行视频发布命令（默认无头）。视频上传后需等待处理完成。\n4. 回传执行结果（成功/失败 + 关键信息）。\n\n## 内容检索与互动流程（搜索/详情/评论/内容数据）\n\n1. 先检查小红书主页登录状态（`XHS_HOME_URL`，非创作者中心）。\n2. 执行 `search-feeds` 获取笔记列表（默认会先抓取搜索下拉推荐词，结果字段为 `recommended_keywords`）。\n3. 若用户需要详情，从搜索结果中取 `id` + `xsecToken` 再执行 `get-feed-detail`。\n4. 若用户需要发表评论，执行 `post-comment-to-feed`（一级评论；必填 `feed_id` / `xsec_token` / `content`）。\n5. 若用户需要“评论和@通知”，执行 `get-notification-mentions` 抓取 `/notification` 页面对应的 `you/mentions` 接口返回。\n6. 若用户需要“笔记基础信息表”，执行 `content-data` 获取曝光/观看/点赞等指标。\n7. 回传结构化结果（数量、核心字段、链接）。\n\n## 常用命令\n\n### 参数顺序提醒（`cdp_publish.py` / `publish_pipeline.py`）\n\n请严格按下面顺序写命令，避免 `unrecognized arguments`：\n\n- 全局参数放在子命令前：`--host --port --headless --account --timing-jitter --reuse-existing-tab`\n- 子命令参数放在子命令后：如 `search-feeds` 的 `--keyword --sort-by --note-type`\n\n示例（正确）：\n\n```bash\npython scripts/cdp_publish.py --reuse-existing-tab search-feeds --keyword \"春招\" --sort-by 最新 --note-type 图文\n```\n\n### 0) 启动 / 测试浏览器（不发布）\n\n默认 CDP 地址为 `127.0.0.1:9222`，可通过 `--host` / `--port` 指定（例如 `10.0.0.12:9222`）。\n\n```bash\n# 启动测试浏览器（有窗口，推荐）\npython scripts/chrome_launcher.py\n\n# 可选-指定端口启动（默认端口为 9222）\npython scripts/chrome_launcher.py --port 9223\n\n# 可选-无头启动测试浏览器\npython scripts/chrome_launcher.py --headless\n\n# 可选-指定端口 + 无头\npython scripts/chrome_launcher.py --headless --port 9223\n\n# 检查当前登录状态\npython scripts/cdp_publish.py check-login\n\n# 可选：优先复用已有标签页（减少有窗口模式下切到前台）\npython scripts/cdp_publish.py --reuse-existing-tab check-login\n\n# 指定端口检查登录\npython scripts/cdp_publish.py --port 9222 check-login\n\n# 指定端口 + 优先复用已有标签页\npython scripts/cdp_publish.py --port 9222 --reuse-existing-tab check-login\n\n# 连接远程 CDP 检查登录（远程 Chrome 需已开启调试端口）\npython scripts/cdp_publish.py --host 10.0.0.12 --port 9222 check-login\n\n# 重启测试浏览器\npython scripts/chrome_launcher.py --restart\n\n# 指定端口重启\npython scripts/chrome_launcher.py --restart --port 9223\n\n# 关闭测试浏览器\npython scripts/chrome_launcher.py --kill\n\n# 指定端口关闭\npython scripts/chrome_launcher.py --kill --port 9223\n```\n\n### 1) 首次登录\n\n```bash\npython scripts/cdp_publish.py login\n\n# 指定端口登录\npython scripts/cdp_publish.py --port 9223 login\n\n# 远程 CDP 登录（不会自动重启远程 Chrome）\npython scripts/cdp_publish.py --host 10.0.0.12 --port 9222 login\n```\n\n### 2) 无头发布 or 有头发布（推荐有窗口发布） 图片 url\n\n```bash\npython scripts/publish_pipeline.py --headless \\\n  --title-file title.txt \\\n  --content-file content.txt \\\n  --image-urls \"URL1\" \"URL2\"\n```\n\n```bash\npython scripts/publish_pipeline.py  --title-file title.txt \\\n  --content-file content.txt \\\n  --image-urls \"URL1\" \"URL2\"\n\n# 可选：优先复用已有标签页（减少有窗口模式下切到前台）\npython scripts/publish_pipeline.py  --reuse-existing-tab --title-file title.txt \\\n  --content-file content.txt \\\n  --image-urls \"URL1\" \"URL2\"\n\n# 远程 CDP 发布（远程 Chrome 需预先启动并可访问）\npython scripts/publish_pipeline.py --host 10.0.0.12 --title-file title.txt \\\n  --content-file content.txt \\\n  --image-urls \"URL1\" \"URL2\"\n```\n\n远程模式说明：当 `--host` 不是 `127.0.0.1/localhost` 时，脚本会跳过本地 `chrome_launcher.py` 的自动启动/重启逻辑。\n\n\n### 3) 无头发布 or 有头发布  使用本地图片发布\n\n```bash\npython scripts/publish_pipeline.py --headless \\\n  --title-file title.txt \\\n  --content-file content.txt \\\n  --images \"./images/pic1.jpg\" \"./images/pic2.jpg\"\n```\n\n```bash\npython scripts/publish_pipeline.py  --title-file title.txt \\\n  --content-file content.txt \\\n  --images \"./images/pic1.jpg\" \"./images/pic2.jpg\"\n```\n\n### 3.5) 视频发布（本地视频文件）\n\n```bash\npython scripts/publish_pipeline.py --headless \\\n\n  --title-file title.txt \\\n  --content-file content.txt \\\n  --video \"C:/videos/my_video.mp4\"\n```\n\n```bash\npython scripts/publish_pipeline.py  --title-file title.txt \\\n  --content-file content.txt \\\n  --video \"C:/videos/my_video.mp4\"\n```\n\n### 3.6) 视频发布（视频 URL）\n\n```bash\npython scripts/publish_pipeline.py --headless \\\n\n  --title-file title.txt \\\n  --content-file content.txt \\\n  --video-url \"https://example.com/video.mp4\"\n```\n\n```bash\npython scripts/publish_pipeline.py  --title-file title.txt \\\n  --content-file content.txt \\\n  --video-url \"https://example.com/video.mp4\"\n```\n\n### 4) 多账号发布 /切换\n\n```bash\npython scripts/cdp_publish.py list-accounts\npython scripts/cdp_publish.py add-account work --alias \"工作号\"\npython scripts/cdp_publish.py --port 9223 --account work login\npython scripts/publish_pipeline.py --port 9223 --account work --headless --title-file title.txt --content-file content.txt --image-urls \"URL1\"\n```\n\n### 5) 搜索内容 / 获取笔记详情\n\n```bash\n# 搜索笔记\npython scripts/cdp_publish.py search-feeds --keyword \"春招\"\n\n# 可选：带筛选搜索\npython scripts/cdp_publish.py --reuse-existing-tab search-feeds --keyword \"春招\" --sort-by 最新 --note-type 图文\n\n# 获取笔记详情（feed_id 与 xsec_token 来自搜索结果）\npython scripts/cdp_publish.py get-feed-detail \\\n  --feed-id 67abc1234def567890123456 \\\n  --xsec-token XSEC_TOKEN\n```\n\n说明：`search-feeds` 输出中包含 `recommended_keywords_count` 与 `recommended_keywords`，表示回车前搜索框下拉推荐词。\n说明：`check-login` 与主页登录检查默认启用本地缓存（12h，仅缓存“已登录”），到期后自动重新网页校验。\n\n### 6) 给笔记发表评论（一级评论）\n\n```bash\n# 直接传评论文本\npython scripts/cdp_publish.py post-comment-to-feed \\\n  --feed-id 67abc1234def567890123456 \\\n  --xsec-token XSEC_TOKEN \\\n  --content \"写得很实用，感谢分享\"\n\n# 使用文件传评论（适合多行文本）\npython scripts/cdp_publish.py post-comment-to-feed \\\n  --feed-id 67abc1234def567890123456 \\\n  --xsec-token XSEC_TOKEN \\\n  --content-file \"/abs/path/comment.txt\"\n```\n\n### 7) 获取内容数据表（content_data）\n\n```bash\n# 获取笔记基础信息表（曝光/观看/封面点击率/点赞/评论/收藏/涨粉/分享/人均观看时长/弹幕）\npython scripts/cdp_publish.py content-data\n\n# 下划线别名\npython scripts/cdp_publish.py content_data\n\n# 可选：导出 CSV\npython scripts/cdp_publish.py --reuse-existing-tab content-data --csv-file \"/abs/path/content_data.csv\"\n```\n\n### 8) 获取评论和@通知（notification mentions）\n\n```bash\n# 抓取 /notification 页面触发的 you/mentions 接口数据\npython scripts/cdp_publish.py get-notification-mentions\n\n# 下划线别名\npython scripts/cdp_publish.py get_notification_mentions\n```\n\n## 失败处理\n\n- 登录失败：提示用户重新扫码登录并重试。\n- 图片下载失败：提示更换图片 URL 或改用本地图片。\n- 页面选择器失效：提示检查 `scripts/cdp_publish.py` 中选择器并更新。\n","topics":["小红书","测试"],"tags":{"latest":"0.1.0"},"stats":{"comments":0,"downloads":1321,"installsAllTime":50,"installsCurrent":22,"stars":1,"versions":1},"createdAt":1772261351053,"updatedAt":1778993859638},"latestVersion":{"version":"0.1.0","createdAt":1772261351053,"changelog":"RedBookSkills v0.1.0 — Initial Release\n\n- Automates publishing of text-image and video content to Xiaohongshu (XHS), plus testing browser control.\n- Supports three tasks: publish text-image, publish video, or start/test browser without publishing.\n- Includes interactive input validation, requiring user confirmation before posting.\n- Handles content search, detail retrieval, commenting, notification mentions, and content metrics.\n- Provides command examples and strict publishing constraints (e.g., title length, image/video exclusivity, headless mode default).\n- Adds multi-account switching and robust error handling with user-friendly prompts.","license":null},"metadata":null,"owner":{"handle":"white0dew","userId":"s17bn8vxjtm8914hp7k9gr722d83nnc9","displayName":"青玉白露","image":"https://avatars.githubusercontent.com/u/49017390?v=4"},"moderation":{"isSuspicious":false,"isMalwareBlocked":false,"verdict":"clean","reasonCodes":["review.llm_review"],"summary":"Review: review.llm_review","engineVersion":"v2.4.24","updatedAt":1779966467038}}