Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twitter / X Scraper: Tweets by Keyword or Handle

Scrape public tweets from X (Twitter) by keyword search, hashtag or user handle. No Twitter API subscription required. Returns tweet text, author, likes, retweets, views, date and media URLs. Pay per tweet delivered. Failed results are never charged.

Run it on Apify: apify.com/themineworks/twitter-x-scraper Docs, FAQ and pricing: themineworks.com/actors/twitter-x-scraper

Price: From $0.90 per 1,000 tweets on Apify's higher plans ($1.50 on the free plan), plus a $0.005 start fee per run. Failed and empty results are never charged.

What it returns

  • Keyword / hashtag search and profile timeline modes
  • Engagement metrics: likes, retweets, replies, views
  • Author verification badge, media URLs, hashtags, mentions
  • Honest login-wall detection with clear no-results record
  • Failed and empty results are never charged

Quick start

You need a free Apify account and its API token (Settings, API & Integrations).

Python

pip install apify-client
from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("themineworks/twitter-x-scraper").call(run_input={
    "searchTerms": [
        "#AI",
        "Anthropic Claude"
    ],
    "handles": [
        "AnthropicAI"
    ],
    "maxTweets": 5,
    "sessionCookies": [
        {
            "name": "auth_token",
            "value": "1a2b3c4d5e6f7g8h9i0j",
            "domain": ".twitter.com",
            "path": "/"
        }
    ]
})

for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

Node.js

npm install apify-client
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: 'YOUR_APIFY_TOKEN' });
const run = await client.actor('themineworks/twitter-x-scraper').call({
    "searchTerms": [
        "#AI",
        "Anthropic Claude"
    ],
    "handles": [
        "AnthropicAI"
    ],
    "maxTweets": 5,
    "sessionCookies": [
        {
            "name": "auth_token",
            "value": "1a2b3c4d5e6f7g8h9i0j",
            "domain": ".twitter.com",
            "path": "/"
        }
    ]
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);

cURL

One request that runs the actor and returns the results in the response (for runs under 5 minutes):

curl -X POST "https://api.apify.com/v2/acts/themineworks~twitter-x-scraper/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"searchTerms": ["#AI", "Anthropic Claude"], "handles": ["AnthropicAI"], "maxTweets": 5, "sessionCookies": [{"name": "auth_token", "value": "1a2b3c4d5e6f7g8h9i0j", "domain": ".twitter.com", "path": "/"}]}'

Command line

This repo includes ready-made clients that save results to JSON and CSV:

python3 twitter_x_scraper.py --token YOUR_APIFY_TOKEN --search-terms "#AI,Anthropic Claude" --handles "AnthropicAI" --max-tweets "5" --session-cookies ""
node twitter_x_scraper.mjs --token YOUR_APIFY_TOKEN --search-terms "#AI,Anthropic Claude" --handles "AnthropicAI" --max-tweets "5" --session-cookies ""

Input

Field Type Default Description
searchTerms array Keywords or hashtags to search for tweets
handles array X usernames to scrape timeline tweets from (without @)
maxTweets integer 20 Maximum tweets to return per search term or handle
searchFilter string "top" Filter search results to top tweets or latest
sessionCookies array Cookie objects from a logged-in X session
useBrowserFallback boolean false Off by default

Output

One row per result, as JSON, CSV, Excel or through the API.

Field Type Description
tweetId string Unique tweet ID from X
tweetUrl string Full URL to the tweet on x.com
authorName string Display name of the tweet author
authorHandle string Username of the tweet author (without @)
authorUrl string URL to the author's X profile
authorVerified boolean Whether the author has a verified / blue checkmark badge
text string Full text content of the tweet
date string ISO 8601 timestamp when the tweet was published
likes integer Number of likes on the tweet
retweets integer Number of retweets / reposts
replies integer Number of replies
views integer View count if visible (not always available)
isRetweet boolean True if this tweet is a repost of another tweet
isReply boolean True if this tweet is a reply to another tweet
mediaUrls array URLs of images or videos attached to the tweet
hashtags array Hashtags extracted from tweet text
mentions array Usernames mentioned in tweet text
source string The search term or @handle that returned this tweet
scraped_at string ISO 8601 timestamp of when the record was scraped

Use it from an AI agent

The actor works as a tool in Claude, Cursor or any MCP client through Apify's MCP server:

https://mcp.apify.com/?tools=themineworks/twitter-x-scraper

FAQ

Does this require a Twitter API key?

No. The actor uses a real browser with residential proxy to access publicly visible X pages, with no Twitter developer account needed.

Why am I getting zero tweets?

X enforces a strict login gate on automated sessions. When X detects a non-authenticated browser, it redirects all requests to the sign-in page. The actor detects this and exits cleanly with no result charges. Results depend on the residential IP assigned to your run.

What data is returned per tweet?

Tweet ID, URL, author name and handle, verified status, tweet text, timestamp, likes, retweets, replies, views, media URLs, hashtags, and @mentions.

Can I filter by top tweets vs latest?

Yes. The searchFilter input accepts "top" or "latest" to control the X search tab used for keyword queries.

Am I charged when X blocks the request?

No. When X returns a login wall instead of results, the run records that plainly and nothing is charged for the attempt.

How much does the Twitter / X Scraper cost?

From $0.90 per 1,000 tweets on Apify's higher plans ($1.50 on the free plan), plus a $0.005 start fee per run. Failed and empty results are never charged. You can cap what a single run may spend with the maximum cost setting on Apify.

Can I export the results to CSV or Excel?

Yes. Every run saves to an Apify dataset you can download as JSON, CSV, Excel or XML, or read through the API. The Python and Node clients in this repo also write the results to local files.

Can I run it on a schedule?

Yes. Save your input as a task on Apify and attach a schedule, or call the API from your own cron job. Scheduled runs are billed the same way as manual ones.

Related scrapers

Part of The Mine Works: 151 pay-per-result scrapers with no login and no browser setup on your side.

License

MIT © The Mine Works

About

Tweets by keyword, hashtag or handle. No paid API key. Python, Node.js and cURL clients for the Twitter / X Scraper on Apify, pay per result.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages