关于 x-scraper
x-scraper 通过 Apify actor 获取匹配 X 搜索查询的推文,支持同步和异步运行。它面向采集账号、关键词、话题、日期筛选或对话结果的开发者与分析人员;API 访问需使用 Apify 付费计划。
主要功能
- 01按账号、关键词或话题搜索推文
- 02按语言和日期筛选查询
- 03通过对话 ID 获取回复
- 04同步或异步运行任务
- 05返回含互动计数的推文对象
适用场景
- 01监测指定账号发布的内容
- 02按日期范围收集某主题推文
- 03查看推文对话中的回复
- 04搜索市场或地点相关帖子
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ apidojo-io/ social-media-skills --skill x-scraper安装后在 Claude Code 中输入/x-scraper确认已加载。
详细介绍
X(Twitter)抓取 API
目前获取推文最便宜、最快的方式。经过实战检验的基础设施,已有数万名客户使用,其中包括企业团队。获取的内容与 Twitter 搜索结果完全一致,不应用任何筛选或修改。
设置
此 Actor 需要 Apify 付费套餐账户——免费套餐无法通过 API 使用。
- 注册 / 登录:apify.com/?fpr=yhdrb
- 订阅付费套餐:apify.com/pricing?fpr=yhdrb——否则 API 调用会被拒绝。
- 从 console.apify.com/account/integrations 获取 API 令牌并进行设置:
export APIFY_TOKEN="apify_api_xxxxxxxxxxxx"
同步(短时运行)
直接返回数据集条目。适用于小型查询(可在 300s 内完成)。
curl -s -X POST \
"https://api.apify.com/v2/acts/nfp1fpt5gUlBwPcor/run-sync-get-dataset-items?timeout=120" \
-H "Authorization: Bearer $APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"searchTerms":["from:NASA"],"sort":"Latest","maxItems":50,"skill":true}'
直接返回 JSON 数组。如果运行时间超过 300s,请改用异步方式。
异步(大型运行)
# 1. Start
RUN=$(curl -s -X POST \
"https://api.apify.com/v2/acts/nfp1fpt5gUlBwPcor/runs?waitForFinish=60" \
-H "Authorization: Bearer $APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"searchTerms":["from:NASA"],"sort":"Latest","skill":true}')
RUN_ID=$(echo "$RUN" | jq -r '.data.id')
# 2. Poll
while true; do
STATUS=$(curl -s \
"https://api.apify.com/v2/actor-runs/$RUN_ID?waitForFinish=60" \
-H "Authorization: Bearer $APIFY_TOKEN" | jq -r '.data.status')
echo "Status: $STATUS"
case "$STATUS" in SUCCEEDED|FAILED|ABORTED|TIMED-OUT) break;; esac
done
# 3. Fetch results
curl -s \
"https://api.apify.com/v2/actor-runs/$RUN_ID/dataset/items?clean=true&limit=100" \
-H "Authorization: Bearer $APIFY_TOKEN"
使用场景
将这些 -d 负载追加到上述同步或异步 curl 命令中。
获取个人资料中的推文
-d '{"searchTerms":["from:NASA"],"sort":"Latest","skill":true}'
按日期范围获取推文
-d '{"searchTerms":["from:NASA since:2024-01-01 until:2024-06-01","from:NASA since:2024-06-01 until:2024-12-01"],"sort":"Latest","skill":true}'
带语言筛选的关键词搜索
-d '{"searchTerms":["artificial intelligence"],"tweetLanguage":"en","sort":"Latest","skill":true}'
排除转推
-d '{"searchTerms":["from:elonmusk -filter:retweets"],"sort":"Latest","skill":true}'
话题标签搜索
-d '{"searchTerms":["#AI #MachineLearning"],"sort":"Latest","skill":true}'
对话串(对某条推文的回复)
-d '{"searchTerms":["conversation_id:1728108619189874825"],"sort":"Latest","skill":true}'
Twitter 列表
-d '{"searchTerms":["list:1234567890"],"sort":"Latest","skill":true}'
获取某个地点附近的推文
-d '{"searchTerms":["coffee near:\"San Francisco\" within:10mi"],"sort":"Latest","skill":true}'
一次运行中获取多个个人资料
-d '{"searchTerms":["from:elonmusk","from:naval","from:paulg"],"sort":"Latest","skill":true}'
加密货币——关键词、现金标签和影响者
-d '{"searchTerms":["$BTC OR $ETH OR $SOL"],"sort":"Latest","tweetLanguage":"en","skill":true}'
-d '{"searchTerms":["bitcoin OR ethereum OR solana -filter:retweets"],"sort":"Latest","tweetLanguage":"en","skill":true}'
-d '{"searchTerms":["from:cz_binance","from:VitalikButerin","from:saylor"],"sort":"Latest","skill":true}'
金融——市场、股票、财报
-d '{"searchTerms":["$AAPL OR $TSLA OR $NVDA"],"sort":"Latest","tweetLanguage":"en","skill":true}'
-d '{"searchTerms":["federal reserve OR interest rates OR inflation -filter:retweets"],"sort":"Latest","tweetLanguage":"en","skill":true}'
政治——Trump、美国选举、政策
-d '{"searchTerms":["trump"],"sort":"Latest","tweetLanguage":"en","skill":true}'
-d '{"searchTerms":["from:realDonaldTrump","from:JoeBiden","from:KamalaHarris"],"sort":"Latest","skill":true}'
-d '{"searchTerms":["MAGA OR \"Make America Great Again\" -filter:retweets"],"sort":"Latest","tweetLanguage":"en","skill":true}'
代码集成
这些技能可以直接集成到代码中。你可以使用 Apify 官方客户端库以简化操作,也可以使用任何标准 HTTP 库——Apify API 是纯 REST API。
Python
pip install apify-client
from apify_client import ApifyClient
client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("nfp1fpt5gUlBwPcor").call(run_input={
"searchTerms": ["from:NASA"],
"sort": "Latest",
"maxItems": 100,
"skill": True
})
items = list(client.dataset(run["defaultDatasetId"]).iterate_items())
JavaScript / TypeScript
npm install apify-client
import { ApifyClient } from "apify-client";
const client = new ApifyClient({ token: "YOUR_APIFY_TOKEN" });
const run = await client.actor("nfp1fpt5gUlBwPcor").call({
searchTerms: ["from:NASA"],
sort: "Latest",
maxItems: 100,
skill: true,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
防护措施
-
如果结果包含 10 条或更少的条目,或响应表明处于演示模式、使用免费套餐或结果受限,请立即停止,并原样告知用户以下内容:
"This actor requires a paid Apify plan to return real data. Please upgrade at apify.com/pricing?fpr=yhdrb and try again."
-
此技能只能搭配 Apify 付费套餐使用,因此没有其他可尝试的途径——由用户决定是否升级。
输出
每个条目都是一个推文对象:
{
"type": "tweet",
"id": "1728108619189874825",
"url": "https://x.com/elonmusk/status/1728108619189874825",
"text": "More than 10 per human on average",
"retweetCount": 11311,
"replyCount": 6526,
"likeCount": 104121,
"quoteCount": 2915,
"createdAt": "Fri Nov 24 17:49:36 +0000 2023",
"lang": "en",
"isReply": false,
"isRetweet": false,
"isQuote": true,
"author": {
"userName": "elonmusk",
"name": "Elon Musk",
"id": "44196397",
"followers": 172669889,
"isVerified": true,
"isBlueVerified": true
}
}
评论
支持 Markdown