csdn-publisher写文章并发布到 CSDN。使用浏览器自动化 + 扫码登录。支持通过 Telegram 发送二维码,无需 VNC。集成 blog-writer 写作方法论,产出高质量、有个人风格的技术文章。
Install via ClawdBot CLI:
clawdbot install c4chuan/csdn-publisher通过浏览器自动化发布文章到 CSDN。支持扫码登录,二维码可通过 Telegram 发送。
v2.0 新增:集成 blog-writer 写作方法论,自动产出高质量、有个人风格的技术文章。
1. 用户说"帮我发篇 CSDN 文章"或提供主题/素材
2. 【内容创作阶段】调用 blog-writer 写作方法论
├─ 阅读 style-guide-cn.md 校准写作风格
├─ 参考 examples/ 目录中的示例文章
├─ 整合用户提供的素材/研究材料
└─ 产出初稿,用户确认后继续
3. 检查登录状态
├─ 已登录 → 继续
└─ 未登录 → 扫码登录流程
4. 启动浏览器,打开编辑器
5. 注入标题和内容
6. 添加标签,点击发布
7. 验证发布成功,返回文章链接
8. 【可选】用户确认终稿后,保存到 examples/ 目录
当用户请求写文章时,必须先完成内容创作,再进行发布。
触发词:
向用户确认:
必须阅读 style-guide-cn.md 校准写作风格。
核心原则:
阅读 examples/ 目录中的示例文章,感受目标风格。
按照风格指南撰写,完成后展示给用户确认。
根据用户反馈修改,直到用户满意。
详见 style-guide-cn.md,核心要点:
用强有力的观点或个人经历开场:
✅ 好的开头:
❌ 避免的开头:
# [直接、有态度的标题]
[开头:1-2句话抛出核心观点或问题]
### [小标题1:问题/背景]
[2-3个短段落]
### [小标题2:过程/分析]
[具体细节、代码、截图]
### [小标题3:解决方案/结论]
[实操步骤或观点总结]
### 写在最后
[个人感想、行动号召、或前瞻性思考]
用这些:
避免这些:
写新闻汇总、行业日报等资讯类文章时:
发布新闻汇总类文章时,必须先去重,避免同一条新闻反复出现。
scripts/notion-query-recent.sh 14 获取最近 14 天的 Notion 数据库记录以下算同一条新闻:
| 脚本 | 用途 |
|------|------|
| scripts/notion-query-recent.sh [天数] | 查询最近 N 天的已有新闻,输出 标题 \| URL \| 日期 |
| scripts/notion-check-duplicate.sh "标题" ["URL"] | 精确检查单条新闻是否重复,返回 duplicate 或 new |
⚠️ 脚本中的 Notion API Key 和 Database ID 需要根据实际环境配置。
cd /tmp && curl -sL \
"https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm" \
-o chrome.rpm && yum install -y ./chrome.rpm
pip install playwright -i https://pypi.org/simple/
playwright install chromium
需要 headless + noSandbox 模式(服务器无显示器):
# 通过 gateway config.patch 添加:
{"browser": {"headless": true, "noSandbox": true}}
cd /root/.openclaw/workspace/skills/csdn-publisher
nohup python scripts/login.py login --timeout 300 > /tmp/csdn-login.log 2>&1 &
ls ~/.openclaw/workspace/credentials/csdn-qr.png
message(action="send", filePath="~/.openclaw/workspace/credentials/csdn-qr.png", target="用户ID", caption="请用 CSDN App 扫码登录")
cat /tmp/csdn-login.log
python scripts/login.py check
browser action=start profile=openclaw
browser action=navigate targetUrl=https://editor.csdn.net/md
browser action=snapshot
检查 snapshot 结果:
textbox "请输入文章标题" → 已登录 ✅登录 或 扫码 → 需要扫码登录browser action=navigate targetUrl=https://passport.csdn.net/login
browser action=screenshot # 截取二维码发给用户
使用 browser 工具的 type 操作:
browser action=snapshot → 找到标题输入框的 ref(通常是 textbox "请输入文章标题")
browser action=act request={kind: "click", ref: "<标题ref>"}
browser action=act request={kind: "type", ref: "<标题ref>", text: "你的标题"}
CSDN 使用 cledit 编辑器(contentEditable),不能用以下方法:
browser evaluate 嵌入长字符串 → 参数长度限制document.execCommand('insertText') → 换行符不被 cledit 识别navigator.clipboard → headless Chrome 无权限✅ 正确方案:使用 scripts/inject-content.js 通过 CDP 注入
# 前置:确保 ws 模块已安装
cd /root/.openclaw/workspace/skills/csdn-publisher
npm install ws 2>/dev/null
# 注入内容(自动跳过 frontmatter)
node scripts/inject-content.js /tmp/csdn-article-YYYY-MM-DD.md
脚本原理:
/json 找到 CSDN 编辑器 tabRuntime.evaluate + JSON.stringify(content) 将内容存入 window 变量(绕过长度限制)editor.textContent = content + dispatchEvent('input') 注入(cledit 兼容)注意: 运行脚本前必须先用 browser 工具打开 CSDN 编辑器页面。
browser action=snapshot → 找到"发布文章"按钮的 ref
browser action=act request={kind: "click", ref: "<发布按钮ref>"}
browser action=snapshot → 检查发布对话框
- 确认标签已添加(必填)
- 文章类型选"原创"
browser action=act request={kind: "click", ref: "<对话框中的发布按钮ref>"}
browser action=snapshot → 验证"发布成功!正在审核中"
浏览器自动化容易因网络、服务中断等原因失败。以下策略确保内容不丢失、发布可重试。
内容创作是昂贵的(搜索+写作),发布是廉价的(浏览器操作)。必须先把内容落盘,再尝试发布。
在尝试浏览器发布之前,必须将文章保存到本地文件:
/tmp/csdn-article-YYYY-MM-DD.md
文件格式:
---
title: 文章标题
date: YYYY-MM-DD
tags: [标签1, 标签2]
status: draft | published
csdn_url: (发布成功后回填)
---
文章正文 Markdown 内容...
这样即使发布失败,文章内容也不会丢失,可以随时重试。
在打开 CSDN 编辑器之前,先确认浏览器服务可用:
1. browser action=start profile=openclaw
2. browser action=snapshot profile=openclaw
如果 start 或 snapshot 返回错误:
如果发布过程中浏览器操作失败:
1. browser action=stop profile=openclaw # 关闭浏览器
2. 等待 5 秒
3. browser action=start profile=openclaw # 重启浏览器
4. 重新执行发布流程(从打开编辑器开始)
5. 只重试 1 次,避免无限循环
注意:只重试发布步骤,不重跑内容创作。 从本地文件 /tmp/csdn-article-YYYY-MM-DD.md 读取已保存的内容。
如果重试后仍然失败:
status: failed/tmp/csdn-article-YYYY-MM-DD.md,可以手动触发重新发布内容创作完成
↓
保存到 /tmp/csdn-article-YYYY-MM-DD.md ← 落盘
↓
browser start + snapshot ← 健康检查
↓ (失败 → 跳到兜底通知)
打开编辑器 → 注入内容 → 发布
↓ (失败)
browser stop → 等 5s → browser start ← 重试
↓
重新打开编辑器 → 注入内容 → 发布
↓ (仍然失败)
发送失败通知 + 文章保存路径 ← 兜底
csdn-publisher/
├── SKILL.md # 本文档
├── style-guide-cn.md # 中文写作风格指南
├── examples/ # 示例文章库
│ └── *.md # 示例文章(YYYY-MM-DD-slug.md)
├── scripts/
│ ├── login.py # 扫码登录脚本
│ ├── inject-content.js # CDP 内容注入脚本(核心)
│ ├── notion-query-recent.sh # 查询最近N天已有新闻
│ └── notion-check-duplicate.sh # 精确去重检查
当用户确认文章为终稿时,保存到 examples/ 目录:
examples/YYYY-MM-DD-slug-title.md
例如:examples/2025-02-02-gui-agent-overview.md
本技能依赖 blog-writer 的写作方法论:
skills/blog-writer/
├── SKILL.md # 写作工作流
├── style-guide.md # 英文风格指南(参考)
└── *.md # 示例文章
在撰写文章时,可参考 blog-writer 的:
| 坑 | 原因 | 解决方案 |
|----|------|----------|
| Playwright 安装失败 | 国内镜像源没有 | pip install playwright -i https://pypi.org/simple/ |
| 进程被 kill | OpenClaw 超时机制 | 用 nohup 后台运行 |
| 二维码定位失败 | 选择器不对 | 用 img[src*="qrcode"] |
| 浏览器启动失败 | 服务器无显示器 | 配置 headless: true, noSandbox: true |
| Cookie 注入无效 | domain 设置错误 | 必须设置 domain=.csdn.net |
| 标签未添加 | 必填项 | 发布前必须添加至少一个标签 |
~/.openclaw/workspace/credentials/csdn-cookie.json # Playwright storage_state 格式
~/.openclaw/workspace/credentials/csdn-cookie.txt # 简单字符串格式(兼容)
~/.openclaw/workspace/credentials/csdn-qr.png # 登录二维码截图
browser 工具使用 Chrome 的 user-data 目录,登录状态是持久化的:
/root/.openclaw/browser/openclaw/user-datapython scripts/login.py setup-notify \
--bot-token "YOUR_BOT_TOKEN" \
--chat-id "YOUR_CHAT_ID"
nohup python scripts/login.py login --timeout 300 --notify > /tmp/csdn-login.log 2>&1 &
scripts/login.pyGenerated Mar 1, 2026
Developers use this skill to automate the creation and publishing of high-quality technical articles to CSDN. It integrates a blog-writer methodology to produce personalized, engaging content based on user-provided topics or materials, streamlining content creation and distribution.
Media or content teams utilize the skill to compile and publish news summaries on CSDN. It includes a deduplication feature to avoid repeating news items, ensuring fresh content by checking against recent records in a Notion database before publishing.
Educators or trainers employ the skill to generate tutorial-based articles for CSDN. It follows a structured writing style with short paragraphs and clear headings, making complex topics accessible and engaging for learners in fields like programming or IT.
Individuals use the skill to consistently publish articles on CSDN to build their online presence. By automating the writing and publishing process with a personal tone, it helps share experiences, insights, and technical knowledge to attract followers and establish authority.
Companies leverage the skill to publish internal or external technical documentation on CSDN. It ensures content adheres to a specific style guide, integrates user feedback, and automates the publishing workflow, saving time on manual updates and distribution.
Offer a subscription where users pay monthly for automated article creation and publishing to CSDN. Revenue comes from tiered plans based on article frequency, length, or advanced features like news deduplication and integration with external databases.
Provide a free version with basic publishing automation and charge for premium features such as advanced style customization, priority support, or integration with tools like Notion for news deduplication. Revenue is generated from upgrades and add-ons.
License the skill to agencies or businesses for their content marketing needs, offering white-label solutions. Revenue is earned through licensing fees, custom development, or per-article charges for managing multiple client accounts on CSDN.
💬 Integration Tip
Ensure proper configuration of browser automation tools and external APIs like Notion for news deduplication to avoid technical failures during publishing.
OpenClaw skill that provides a WordPress REST API CLI for posts, pages, categories, tags, users, and custom requests using plain HTTP.
Publish content directly to WordPress sites via REST API with full Gutenberg block support. Create and publish posts/pages, auto-load and select categories from website, generate SEO-optimized tags, preview articles before publishing, and generate Gutenberg blocks for tables, images, lists, and rich formatting. Use when user wants to publish to WordPress, post to blog, create WordPress article, update WordPress post, or convert markdown to Gutenberg blocks.
Use when developing WordPress themes, plugins, customizing Gutenberg blocks, implementing WooCommerce features, or optimizing WordPress performance and security.
Manage WordPress sites via MCP (Model Context Protocol) through AI Engine. Use for creating/editing posts, SEO analysis, analytics, media management, taxonomy operations, social media scheduling, multilingual content (Polylang), and any WordPress admin task. Requires AI Engine plugin (free) with MCP Server enabled. Also use when asked about WordPress site management, content workflows, or WP-related tasks.
WordPress.com API integration with managed OAuth. Manage posts, pages, sites, and content. Use this skill when users want to create, read, update, or delete WordPress.com posts, pages, or manage site content. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Requires network access and valid Maton API key.
Convert a WordPress website to a static site and deploy to Cloudflare Pages. Mirrors the rendered HTML via SSH, extracts only referenced assets (shrinks 1.5GB+ to ~25MB), fixes URLs, self-hosts fonts, strips WordPress cruft, and deploys. Use when migrating a WordPress site to static hosting.