X文章出口商
出口 X(推特)文章 作为高质量的PDF文件,具有可选的翻译和暗模式。
截图
Light mode Dark mode
特性
- 命令行界面 --从终端将任何X文章URL导出为PDF
- 翻译 --通过本地翻译文章 奥拉玛 + 翻译法 (55种以上语言)
- 深色模式 --黑色背景渲染与X的深色主题相匹配
- HTTP API --具有异步作业处理、速率限制和承载身份验证的自托管服务器
- MCP服务器 --用作 克劳德代码 从对话中导出文章的工具
- 质量验证 --通过以下方式进行结构PDF检查 pdfcpu +文本提取验证
先决条件
安装
go install github.com/annismckenzie/x-article-exporter@latest或者从源代码构建:
git clone https://github.com/annismckenzie/x-article-exporter.git
cd x-article-exporter
go build -o x-article-exporter .快速开始
1.获取身份验证Cookie
打开 x.com 在浏览器中,然后:
- 打开DevTools(F12或Cmd+选项+I)
- 首选 应用 > Cookie >
https://x.com - 复制以下值
auth_token和ct0
2.创建配置文件
保存到 ~/.config/x-article-exporter/config.yaml:
auth_token: "your-auth-token"
ct0: "your-ct0"3.出口物品
x-article-exporter https://x.com/user/article/1234567890这将在以文章标题命名的当前目录中创建一个PDF。
配置
所有设置都进入 ~/.config/x-article-exporter/config.yaml.CLI标志覆盖配置值。
# Required: X authentication cookies (get from browser dev tools)
auth_token: "your-auth-token"
ct0: "your-ct0"
# Optional: Ollama model for translation (default: translategemma:12b)
# ollama_model: "translategemma:12b"
# Optional: Render PDFs in dark mode
# dark_mode: true
# Server mode configuration (used with --serve)
server:
port: 8080
host: "127.0.0.1"
job_ttl_minutes: 60
default_rate_limit_per_hour: 20
max_concurrent_jobs: 4
api_keys:
- key: "your-api-key-here"
name: "default"
# rate_limit_per_hour: 20 # omit to use default_rate_limit_per_hour看 config.example.yaml 以获取完整参考。
用法
命令行界面
x-article-exporter [flags]
| 标志 | 描述 |
|---|---|
-auth-token 十、 auth_token cookie(覆盖配置) | |
-ct0 十、 ct0 cookie(覆盖配置) | |
-translate | 翻译成目标语言(例如。 de, fr, ja) |
-dark | 在暗模式下渲染PDF |
-output | 输出PDF路径(默认: ./{title}.pdf) |
-query-id | GraphQL查询ID覆盖(如果省略,则自动解析) |
-ollama-model | Ollama翻译模型(默认值: translategemma:12b) |
示例:
# Basic export
x-article-exporter https://x.com/elonmusk/article/1234567890
# Translate to German
x-article-exporter -translate de https://x.com/elonmusk/article/1234567890
# Dark mode with custom output path
x-article-exporter -dark -output ~/Documents/article.pdf https://x.com/elonmusk/article/1234567890HTTP API
启动服务器:
x-article-exporter --serve导出工作流程:
# Submit an article for export
curl -X POST -H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{"url":"https://x.com/user/article/123"}' \
http://localhost:8080/export
# Check job status
curl -H "Authorization: Bearer your-api-key" \
http://localhost:8080/export/{id}
# Download the PDF
curl -H "Authorization: Bearer your-api-key" \
http://localhost:8080/export/{id}/pdf -o article.pdf看 API.md 用于请求/响应模式的完整端点引用。
MCP服务器(克劳德代码)
注册成为Claude Code工具:
claude mcp add x-article-exporter /path/to/x-article-exporter -- --mcp然后问克劳德: *“将此文章导出为PDF:https://x.com/user/article/123"*
看 docs/mcp-setup.md 了解完整的设置指南、可用工具和故障排除。
运作原理
- 提取 -通过X的GraphQL API获取文章(
TweetResultByRestId),解析Draft.js内容模型 - 翻译 *(可选)* --将文本块批量发送到运行translategemma的本地Ollama实例
- 渲染 --从文章模型生成Typst源代码,编译为嵌入字体和图像的PDF
- 验证 --使用pdfcpu运行结构检查并验证文本提取
贡献
# Run tests
make test
# Run end-to-end test (requires auth config)
make test-article
# Visual preview (generates PDF + PNGs)
make preview
make preview-dark建筑和设计文件在 shaping/.
