把用户给的标题、正文、图片(可选)或 docx 文档发布到头条号后台。优先使用 cookie_header 参数登录;未提供 cookie 时使用已保存的会话文件。
title + content(或 content_file)+ 可选 images
cookie_header,希望无交互登录并发文
title:字符串,必填
content:字符串,必填(纯文本)
images:字符串数组,可选(服务器上的图片绝对路径)
docx:可选;如使用固定目录投放,可不传,由脚本自动取第一个 .docx
docx_wait_seconds:可选,整数;docx 导入后的等待秒数,默认 60,可设为 90、120
cookie_header:字符串,可选(形如 a=b; c=d; ...,来自浏览器对 mp.toutiao.com 的 Cookie)
publish:布尔值,可选;默认 false(只填充不发布,避免误发)
在腾讯云 Ubuntu 上执行(项目固定路径):
cd /home/ubuntu/projects/toutiao_poster
只填充不发布:
TOUTIAO_COOKIE='<cookie_header>' \
./.venv/bin/python -m toutiao_poster post \
--title '<title>' \
--content-text '<content>' \
--headless
发布:
TOUTIAO_COOKIE='<cookie_header>' \
./.venv/bin/python -m toutiao_poster post \
--title '<title>' \
--content-text '<content>' \
--docx-wait-seconds 60 \
--headless \
--publish
带图片(多张图重复传 --image):
TOUTIAO_COOKIE='<cookie_header>' \
./.venv/bin/python -m toutiao_poster post \
--title '<title>' \
--content-text '<content>' \
--image '/abs/path/1.png' \
--image '/abs/path/2.jpg' \
--docx-wait-seconds 60 \
--headless \
--publish
./.venv/bin/python -m toutiao_poster post \
--title '<title>' \
--content-text '<content>' \
--docx-wait-seconds 60 \
--headless \
--publish
当 OpenClaw 把图片保存到固定目录时,不需要传 --image,脚本会自动读取并上传:
/home/ubuntu/projects/artifacts/toutiaopic
./artifacts/toutiaopic(以运行时 cwd 为准)
/home/ubuntu/projects/toutiao_poster/artifacts/toutiaopic
/home/ubuntu/projects/toutiao_poster/.toutiao_poster/artifacts/toutiaopic
<图片目录>/done/
TOUTIAO_IMAGE_DIR=/abs/path/to/toutiaopic
示例(无需传 --image):
TOUTIAO_COOKIE='<cookie_header>' \
./.venv/bin/python -m toutiao_poster post \
--title '<title>' \
--content-text '<content>' \
--headless \
--publish
当 OpenClaw 把 docx 保存到固定目录时,不需要额外传文档路径,脚本会自动读取目录中的第一个 .docx:
/home/ubuntu/projects/toutiao_poster/.toutiao_poster/artifacts/toutiaodoc/
/home/ubuntu/projects/toutiao_poster/.toutiao_poster/artifacts/toutiaodoc/done/
docx_wait_seconds 等待文档解析,默认 60 秒
示例(只要目录里有 docx,就会优先导入该 docx):
TOUTIAO_COOKIE='<cookie_header>' \
./.venv/bin/python -m toutiao_poster post \
--title '<title>' \
--content-text '<content>' \
--docx-wait-seconds 90 \
--headless \
--publish
说明:
--docx-wait-seconds 调大到 90 或 120
done/
/home/ubuntu/projects/toutiao_poster/.toutiao_poster/artifacts/
.docx 放入 toutiaodoc/
共 1 个版本