Install
openclaw skills install kevin-toutiao-auto-publisher自动发布图文文章和微头条到头条号,支持选题、写文、配图生成、Cookie登录、图文混排发布的全自动流程,也可定时自动化执行。
openclaw skills install kevin-toutiao-auto-publisher全自动发布图文文章和微头条到头条号的 AI Agent Skill。
复制 config/account_config.json.example 为 config/account_config.json,填入你的信息:
{
"account_id": "你的头条账号ID",
"account_name": "你的头条号名称",
"cookie_file": "/path/to/toutiao_cookies.json",
"inject_script": "/path/to/inject_cookies.sh",
"feishu_config": {
"app_id": "可选,飞书机器人APP_ID",
"app_secret": "可选,飞书机器人APP_SECRET",
"open_id": "可选,飞书通知接收人OPEN_ID"
}
}
pip install playwright
playwright install chromium
pip install -r requirements.txt
安装此 Skill 后,直接用自然语言指示 Agent:
Agent 会自动完成:选题 → 内容生成 → 配图生成 → Cookie 注入 → 发布 → 通知
# 发布图文文章
python3 scripts/publish_article.py
python3 scripts/publish_article.py --topic "中年困境"
python3 scripts/publish_article.py --no-publish # 只生成不发布
# 发布微头条
python3 scripts/publish_weitoutiao.py
python3 scripts/publish_weitoutiao.py --content "你的内容"
python3 scripts/publish_weitoutiao.py --auto-topic # 自动选题
# 定时自动化
python3 scripts/run_scheduler.py --type article
python3 scripts/run_scheduler.py --type weitoutiao
python3 scripts/run_scheduler.py --type both
选题/指定话题 → 生成文章内容 → 生成1张水墨风配图
→ Cookie注入登录 → 导航到发布页 → 填写标题 → 填写正文
→ 插入配图到正文 → 设置封面 → 勾选声明 → 发布 → 通知
发布 URL:https://mp.toutiao.com/profile_v4/graphic/publish
关键步骤:
insertHTML 一次性插入段落获取热门话题 → 生成短内容(~200字) → 生成配图
→ Cookie注入登录 → 导航到微头条发布页 → 填写内容
→ 上传配图 → 发布 → 通知
发布 URL:https://mp.toutiao.com/profile_v4/weitoutiao/publish
| 字段 | 必填 | 说明 |
|---|---|---|
| account_id | 是 | 头条账号 ID |
| account_name | 是 | 头条号名称 |
| cookie_file | 是 | Cookie JSON 文件路径 |
| inject_script | 否 | Cookie 注入脚本路径 |
| feishu_config | 否 | 飞书通知配置 |
{
"article": {
"enabled": true,
"schedule": "0 * 6-23 * * *",
"max_retries": 3,
"timeout": 300
},
"weitoutiao": {
"enabled": true,
"schedule": "0 * 6-23 * * *",
"auto_select_topic": true,
"timeout": 180
}
}
from core.playwright_publisher import PlaywrightPublisher
pub = PlaywrightPublisher(headless=False, account_name="你的账号名")
await pub.start() # 启动 CDP 连接
await pub.load_cookies("/path/to/cookies.json") # 注入 Cookie
await pub.navigate_to_publish() # 导航到发布页
await pub.fill_title("文章标题") # 填写标题
await pub.fill_content("文章正文") # 填写正文
await pub.insert_image("/path/to/img.png") # 插入正文配图
await pub.upload_cover_image("/path/to/img.png") # 设置封面
await pub.check_declarations() # 勾选声明
success = await pub.publish() # 发布
from core.publisher import PublisherManager
pub = PublisherManager(config_file="config/account_config.json")
# 图文发布
result = await pub.publish_article(
title="标题", content="内容",
images=["/path/to/img1.png"],
options={"personal_view": True}
)
# 微头条发布
result = await pub.publish_weitoutiao(
content="微头条内容", image="/path/to/img.png"
)
# 获取热门话题
topics = await pub.get_topic_invitations()
topic = pub.get_hot_topic(topics) # 围观最多的话题
支持通过 AI 工具自动生成水墨中国风配图:
# 推荐提示词模板
prompt = "水墨中国风画,竹子,宣纸底色,红色印章,极简留白"
size = "1024x1024"
风格关键词:竹子、宣纸、红色印章、极简、留白、山水、松树
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 发布失败,提示重新登录 | Cookie 过期 | 重新获取 Cookie(有效期约30天) |
| 封面上传失败 | DOM 选择器变化 | 查看 logs/ 目录截图调试 |
| 配图生成失败 | AI 服务不可用 | 检查网络或换时段重试 |
| 预览对话框未弹出 | 页面加载慢 | 增加等待时间或检查截图 |
| 定时任务不执行 | schedule 配置错误 | 检查 automation_settings.json |
| AI 助手抽屉遮挡操作 | 头条 SPA 的 AI 浮层 | 自动用 JS 隐藏所有 drawer |
toutiao-publisher/
├── SKILL.md # 本文件(ClawHub 标准格式)
├── README.md # 详细文档
├── requirements.txt # Python 依赖
├── config/
│ ├── account_config.json.example # 账号配置模板
│ └── automation_settings.json # 自动化设置
├── core/
│ ├── playwright_publisher.py # Playwright 自动化发布引擎
│ ├── publisher.py # API 方式发布器
│ ├── article_generator.py # 文章内容生成
│ ├── image_generator.py # 配图生成
│ ├── cookie_manager.py # Cookie 管理
│ └── notifier.py # 通知系统
├── scripts/
│ ├── publish_article.py # 图文发布脚本
│ ├── publish_weitoutiao.py # 微头条发布脚本
│ └── run_scheduler.py # 定时任务脚本
├── templates/
│ ├── article_prompts/ # 文章生成提示词
│ └── weitoutiao_prompts/ # 微头条提示词
└── logs/ # 日志目录
.gitignore 忽略 config/account_config.jsonMIT License - 欢迎自由使用和修改
v2.0.0 - 包含完整代码,通用化配置,可直接使用