关于 x-tweet-fetcher
用于获取 X/Twitter 公开内容的命令行工具和 Python 库,支持推文、时间线、搜索和提及监控。它可在多个后端间路由,部分任务需要 Nitter 或浏览器。
主要功能
- 01获取单条推文和用户资料
- 02读取回复串和用户时间线
- 03搜索推文并监控提及
- 04读取 X 列表和文章
- 05在 Nitter 与浏览器后端间路由
适用场景
- 01收集推文正文、作者、互动数据和媒体链接
- 02查看用户时间线或搜索推文
- 03跟踪某个账号的新提及
- 04获取 X 列表或文章内容
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ ythx-101/ x-tweet-fetcher --skill x-tweet-fetcher安装后在 Claude Code 中输入/x-tweet-fetcher确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
.gitignorepyproject.tomlLICENSEMIGRATION.mdCHANGELOG.mdVERSIONREADME.md.github/workflows/ci.ymldocs/e2e-integration.mdscripts/fetch_tweet.pysrc/xtf/__init__.pycli.pyconfig.pyexceptions.pyhttp.pyi18n.pyledger.pymonitor.pymodels.pysrc/xtf/backends/__init__.pybase.py_camofox_driver.py_playwright_driver.pybrowser.pynitter.pyfxtwitter.pysrc/xtf/parsers/__init__.pyfxtwitter_json.pynitter_html.pyurls.py详细介绍
X 推文抓取器
无需身份验证即可抓取 X/Twitter 推文。如需了解 Agent 使用案例、故障和实地报告,请从 #22 Teahouse / 茶座 开始。
功能概览
| 功能 | 命令 | 依赖项 |
|---|---|---|
| 单条推文 | xtf --url <tweet_url> | 无(零依赖) |
| 回复串 | xtf --url <tweet_url> --replies | Nitter 或浏览器 |
| 用户时间线 | xtf --user <username> --limit 50 | Nitter 或浏览器 |
| 搜索 | xtf --search "<query>" | Nitter |
| 用户资料 | xtf --user-info <username> | 无(零依赖) |
| X 列表 | xtf --list <list_url_or_id> | 浏览器(Camofox/Playwright) |
| X 文章 | xtf --article <url_or_id> | 浏览器(Camofox/Playwright) |
| 提及监控 | xtf --monitor @<username> | Nitter 或浏览器 |
python3 scripts/fetch_tweet.py 接受相同的标志(兼容 v1 的入口点)。
基本用法(零依赖)
# JSON output (default)
xtf --url https://x.com/user/status/1234567890
# Human-readable
xtf --url https://x.com/user/status/1234567890 --text-only
# Output covers: text, author, stats (likes/retweets/views), media URLs,
# quoted tweets, and full article text for tweet-embedded articles.
时间线 / 搜索 / 回复(Nitter)
export XTF_NITTER=http://127.0.0.1:8788 # your instance; comma-separate for failover
xtf --user elonmusk --limit 20
xtf --search "openclaw" --limit 10
xtf --url https://x.com/user/status/123 --replies
后端选择:--backend auto(默认,优先使用 Nitter,然后使用浏览器)、--backend nitter、--backend browser。
列表和文章(浏览器)
# Camofox running on localhost:9377 (default), or:
export XTF_BROWSER=playwright
xtf --list https://x.com/i/lists/1455045069516357634 --limit 30
xtf --article https://x.com/i/article/2011779830157557760
注意:获取完整的 X 文章文本需要登录 X;未登录时会返回标题和公开预览(is_partial: true)。
提及监控(适合 cron)
xtf --monitor @yourhandle
# exit 0 = no new mentions, 1 = new mentions found, 2 = setup error
# First run builds a baseline silently; later runs report only new URLs.
Agent 错误处理
每个错误结果都包含 error(消息)和 error_code:
invalid_input · not_found · rate_limited · upstream_down · backend_unavailable · all_backends_failed(附带各后端的 error_causes)。
Python API
from xtf import Router
router = Router()
tweets = router.fetch_timeline("elonmusk", limit=20) # list[Tweet]
print(tweets[0].to_dict())
目录结构
src/xtf/
├── backends/ # fxtwitter.py, nitter.py, browser.py
├── parsers/ # pure parsing functions, fixture-tested
├── router.py # auto-fallback
├── monitor.py # mentions monitor
└── cli.py # the `xtf` command
scripts/fetch_tweet.py # v1-compatible shim
想要抓取中文平台(微博/Bilibili/微信)或追踪推文增长?这些功能已在 v2 中移出本仓库,请参阅 MIGRATION.md。
评论
支持 Markdown