res-x
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseX/Twitter Fetch & Search
X/Twitter 内容抓取与搜索
Fetch tweet content by URL and search X posts using xAI Responses API with Grok's tool. Solves the problem of X/Twitter blocking WebFetch with "JavaScript disabled" errors.
x_search借助Grok的工具,通过xAI Responses API实现通过URL抓取推文内容、搜索X帖子的功能,解决了X/Twitter以「JavaScript未启用」错误拦截WebFetch抓取的问题。
x_searchArchitecture
架构
| Capability | API Tool | Cost |
|---|---|---|
| Fetch tweet by URL | xAI | ~$0.005/call |
| Search X | xAI | ~$0.005/call |
Fetching batches URLs in groups of 3 per API call to reduce cost.
| 能力 | API工具 | 成本 |
|---|---|---|
| 按URL抓取推文 | xAI | 单次调用约$0.005 |
| 搜索X内容 | xAI | 单次调用约$0.005 |
每次API调用将URL按3个一组批量处理以降低成本。
Prerequisites
前置条件
Required Tools
所需工具
| Tool | Purpose | Install |
|---|---|---|
| uv | Python package manager (handles dependencies) | |
| 工具 | 用途 | 安装方式 |
|---|---|---|
| uv | Python包管理器(处理依赖) | |
API Key
API密钥
| Service | Purpose | Required | Get Key |
|---|---|---|---|
| xAI | X/Twitter access via Grok | Yes | https://console.x.ai |
This skill requires an xAI API key. There is no fallback mode.
| 服务 | 用途 | 是否必填 | 密钥获取地址 |
|---|---|---|---|
| xAI | 通过Grok访问X/Twitter | 是 | https://console.x.ai |
本工具需要xAI API密钥,无备用运行模式。
Keychain Setup (One-Time)
密钥链设置(仅需配置一次)
bash
undefinedbash
undefined1. Create a dedicated keychain (skip if already exists)
1. 创建专用密钥链(如果已存在可跳过)
security create-keychain -p 'YourPassword' ~/Library/Keychains/claude-keys.keychain-db
security create-keychain -p 'YourPassword' ~/Library/Keychains/claude-keys.keychain-db
2. Add keychain to search list
2. 将密钥链添加到搜索列表
security list-keychains -s ~/Library/Keychains/claude-keys.keychain-db ~/Library/Keychains/login.keychain-db /Library/Keychains/System.keychain
security list-keychains -s ~/Library/Keychains/claude-keys.keychain-db ~/Library/Keychains/login.keychain-db /Library/Keychains/System.keychain
3. Store your xAI API key
3. 存储你的xAI API密钥
echo -n "Enter xAI API key: " && read -s key && security add-generic-password -s "xai-api" -a "$USER" -w "$key" ~/Library/Keychains/claude-keys.keychain-db && unset key && echo
Before using: `security unlock-keychain ~/Library/Keychains/claude-keys.keychain-db`echo -n "Enter xAI API key: " && read -s key && security add-generic-password -s "xai-api" -a "$USER" -w "$key" ~/Library/Keychains/claude-keys.keychain-db && unset key && echo
使用前执行:`security unlock-keychain ~/Library/Keychains/claude-keys.keychain-db`Script Usage
脚本用法
bash
undefinedbash
undefinedFetch single tweet
抓取单条推文
uv run scripts/x_fetch.py fetch "https://x.com/user/status/123456"
uv run scripts/x_fetch.py fetch "https://x.com/user/status/123456"
Fetch multiple tweets (batched, 3 per API call)
抓取多条推文(批量处理,每次API调用处理3条)
uv run scripts/x_fetch.py fetch "url1" "url2" "url3" "url4" "url5"
uv run scripts/x_fetch.py fetch "url1" "url2" "url3" "url4" "url5"
Force one-per-URL for max fidelity
强制每个URL单独调用以获得最高保真度
uv run scripts/x_fetch.py fetch "url1" "url2" --single
uv run scripts/x_fetch.py fetch "url1" "url2" --single
Search X
搜索X内容
uv run scripts/x_fetch.py search "query terms"
uv run scripts/x_fetch.py search "query terms" --quick
uv run scripts/x_fetch.py search "query terms"
uv run scripts/x_fetch.py search "query terms" --quick
JSON output (both commands)
输出JSON格式结果(上述两个命令均支持)
uv run scripts/x_fetch.py fetch "url" --json
uv run scripts/x_fetch.py search "query" --json
undefineduv run scripts/x_fetch.py fetch "url" --json
uv run scripts/x_fetch.py search "query" --json
undefinedWorkflow
工作流程
Step 0: Detect xAI Key (Mandatory)
步骤0:检测xAI密钥(必填)
Run before every invocation:
bash
security find-generic-password -s "xai-api" -w ~/Library/Keychains/claude-keys.keychain-db 2>/dev/null && echo "XAI_AVAILABLE=true" || echo "XAI_AVAILABLE=false"If , report that this skill requires an xAI key and show the keychain setup instructions above.
XAI_AVAILABLE=false每次调用前运行:
bash
security find-generic-password -s "xai-api" -w ~/Library/Keychains/claude-keys.keychain-db 2>/dev/null && echo "XAI_AVAILABLE=true" || echo "XAI_AVAILABLE=false"如果,提示本工具需要xAI密钥并展示上述密钥链设置指引。
XAI_AVAILABLE=falseStep 1: Detect Intent
步骤1:识别意图
- URLs present in user input or referenced note -> fetch
- Query text only -> search
- 用户输入或引用的笔记中存在URL → 执行抓取
- 仅包含查询文本 → 执行搜索
Step 2: Execute
步骤2:执行操作
For fetch:
- Extract all X/Twitter URLs from user input or referenced file
- Run the script with all URLs as arguments
- The script batches them (3 per API call) automatically
For search:
- Run the script with the search query
- Use for fast overview, omit for deeper results
--quick
抓取场景:
- 从用户输入或引用的文件中提取所有X/Twitter URL
- 将所有URL作为参数运行脚本
- 脚本自动将URL按3个一组批量处理
搜索场景:
- 携带搜索查询词运行脚本
- 如需快速概览使用参数,如需更深度的结果则省略该参数
--quick
Step 3: Present Results
步骤3:展示结果
- For fetch: present tweet-by-tweet with full content, engagement, thread/quote context
- For search: present as a list with engagement metrics
- 抓取场景:逐推文展示完整内容、互动数据、推文串/引用上下文
- 搜索场景:以列表形式展示附带互动指标的结果
URL Patterns Accepted
支持的URL格式
https://x.com/{user}/status/{id}
https://twitter.com/{user}/status/{id}
https://x.com/{user}/status/{id}?s=20
https://x.com/{user}/status/{id}?t=...&s=...
https://x.com/i/article/{id}Tweets normalized to , articles to before processing.
https://x.com/{user}/status/{id}https://x.com/i/article/{id}https://x.com/{user}/status/{id}
https://twitter.com/{user}/status/{id}
https://x.com/{user}/status/{id}?s=20
https://x.com/{user}/status/{id}?t=...&s=...
https://x.com/i/article/{id}处理前会将推文统一格式化为,文章统一格式化为。
https://x.com/{user}/status/{id}https://x.com/i/article/{id}Batch Processing
批量处理
For processing saved X links from a file (e.g., Obsidian daily note):
- Read the file content
- Extract all X/Twitter URLs (tweets: , articles:
https?://(?:x\.com|twitter\.com)/\w+/status/\d+)https?://(?:x\.com|twitter\.com)/i/article/[\w\-]+ - Pass all URLs to the script:
uv run scripts/x_fetch.py fetch "url1" "url2" ... - Present results organized by URL
如需处理保存在文件(例如Obsidian每日笔记)中的X链接:
- 读取文件内容
- 提取所有X/Twitter URL(推文匹配规则:,文章匹配规则:
https?://(?:x\.com|twitter\.com)/\w+/status/\d+)https?://(?:x\.com|twitter\.com)/i/article/[\w\-]+ - 将所有URL传递给脚本:
uv run scripts/x_fetch.py fetch "url1" "url2" ... - 按URL分类展示结果
Cost
成本说明
| Action | API Calls | Cost |
|---|---|---|
| Fetch 1-3 tweets | 1 | ~$0.005 |
| Fetch 4-6 tweets | 2 | ~$0.010 |
| Fetch 10 tweets | 4 | ~$0.020 |
| Fetch 10 tweets (--single) | 10 | ~$0.050 |
| X search | 1 | ~$0.005 |
| X search (--quick) | 1 | ~$0.005 |
| 操作 | API调用次数 | 成本 |
|---|---|---|
| 抓取1-3条推文 | 1 | 约$0.005 |
| 抓取4-6条推文 | 2 | 约$0.010 |
| 抓取10条推文 | 4 | 约$0.020 |
| 抓取10条推文(使用--single参数) | 10 | 约$0.050 |
| X搜索 | 1 | 约$0.005 |
| X搜索(使用--quick参数) | 1 | 约$0.005 |
Constraints
使用约束
DO:
- Run Step 0 before every invocation
- Validate URLs before calling the script
- Use when parsing results programmatically
--json - Present full tweet content without truncation
DON'T:
- Try WebFetch on X URLs (fails with JS disabled)
- Skip the xAI key check
- Use this for general web search (use or
res-web)res-deep
允许的操作:
- 每次调用前执行步骤0的密钥检测
- 调用脚本前校验URL有效性
- 程序化解析结果时使用参数
--json - 完整展示推文内容不做截断
禁止的操作:
- 尝试对X URL使用WebFetch(会因JavaScript未启用报错失败)
- 跳过xAI密钥检测步骤
- 将本工具用于通用网页搜索(请使用或
res-web)res-deep
Troubleshooting
故障排查
xAI key not found:
bash
security find-generic-password -s "xai-api" ~/Library/Keychains/claude-keys.keychain-dbIf not found, run keychain setup above.
Keychain locked:
bash
security unlock-keychain ~/Library/Keychains/claude-keys.keychain-dbScript errors: Ensure uv is installed:
which uv找不到xAI密钥:
bash
security find-generic-password -s "xai-api" ~/Library/Keychains/claude-keys.keychain-db如果未查询到结果,请运行上述密钥链设置步骤。
密钥链已锁定:
bash
security unlock-keychain ~/Library/Keychains/claude-keys.keychain-db脚本报错: 确认已安装uv:
which uv