mcpField
X
x-tweet-fetcher

x-tweet-fetcher

github.com/ythx-101数据与数据库994454 次安装2 周前更新
代码仓库

关于 x-tweet-fetcher

用于获取 X/Twitter 公开内容的命令行工具和 Python 库,支持推文、时间线、搜索和提及监控。它可在多个后端间路由,部分任务需要 Nitter 或浏览器。

主要功能

  1. 01获取单条推文和用户资料
  2. 02读取回复串和用户时间线
  3. 03搜索推文并监控提及
  4. 04读取 X 列表和文章
  5. 05在 Nitter 与浏览器后端间路由

适用场景

  1. 01收集推文正文、作者、互动数据和媒体链接
  2. 02查看用户时间线或搜索推文
  3. 03跟踪某个账号的新提及
  4. 04获取 X 列表或文章内容

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/ythx-101/x-tweet-fetcher --skill x-tweet-fetcher

安装后在 Claude Code 中输入/x-tweet-fetcher确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

.gitignore
pyproject.toml
LICENSE
MIGRATION.md
CHANGELOG.md
VERSION
README.md
.github/workflows/
ci.yml
docs/
e2e-integration.md
scripts/
fetch_tweet.py
src/xtf/
__init__.py
cli.py
config.py
exceptions.py
http.py
i18n.py
ledger.py
monitor.py
models.py
src/xtf/backends/
__init__.py
base.py
_camofox_driver.py
_playwright_driver.py
browser.py
nitter.py
fxtwitter.py
src/xtf/parsers/
__init__.py
fxtwitter_json.py
nitter_html.py
urls.py

详细介绍

X 推文抓取器

无需身份验证即可抓取 X/Twitter 推文。如需了解 Agent 使用案例、故障和实地报告,请从 #22 Teahouse / 茶座 开始。

功能概览

功能命令依赖项
单条推文xtf --url <tweet_url>无(零依赖)
回复串xtf --url <tweet_url> --repliesNitter 或浏览器
用户时间线xtf --user <username> --limit 50Nitter 或浏览器
搜索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