# X-Scrapper/Twitter-Scraper (`akshaynceo/x-scrapper-twitter-scraper`) Actor

- **URL**: https://apify.com/akshaynceo/x-scrapper-twitter-scraper.md
- **Developed by:** [AKSHAY N](https://apify.com/akshaynceo) (community)
- **Categories:** AI, Automation
- **Security:** Limited permissions
- **Stats:** 325 total users, 1 monthly users, 84.8% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Twitter/X Scraper (Python)

A powerful Apify actor to scrape Twitter/X data **without requiring authentication**. Uses Playwright for browser automation and extracts data directly from the Twitter/X website.

### Features

✅ **No Authentication Required** - Works without login cookies\
✅ **Search Tweets** - Find tweets by keywords, hashtags\
✅ **User Timelines** - Get tweets from any public user\
✅ **User Profiles** - Extract profile information\
✅ **Media & Replies** - Filter for specific content types\
✅ **Engagement Metrics** - Likes, retweets, replies, views\
✅ **Anti-Detection** - Built-in stealth features

### How It Works

1. **Playwright Browser** - Uses a real browser to access Twitter
2. **Guest Token** - Obtains guest credentials automatically
3. **DOM Extraction** - Parses tweets directly from the page
4. **Infinite Scroll** - Automatically scrolls to load more tweets

### Input Parameters

#### Search Configuration

| Parameter | Type | Description |
|-----------|------|-------------|
| `search_terms` | Array | Search queries (e.g., `#AI`, `bitcoin`) |
| `usernames` | Array | Twitter usernames to scrape (without @) |
| `tweet_urls` | Array | Direct URLs to specific tweets |

#### Scraping Options

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `scrape_type` | String | `tweets` | What to scrape: `tweets`, `profile`, `replies`, `media` |
| `max_tweets` | Integer | 50 | Maximum tweets per search/user |
| `include_replies` | Boolean | false | Include reply tweets |
| `include_retweets` | Boolean | true | Include retweets |

#### Filters

| Parameter | Type | Description |
|-----------|------|-------------|
| `min_likes` | Integer | Minimum likes filter |
| `min_retweets` | Integer | Minimum retweets filter |

### Output Format

#### Tweet Data

```json
{
    "tweet_id": "1234567890",
    "text": "Tweet content here...",
    "author_name": "Elon Musk",
    "author_username": "elonmusk",
    "likes": 50000,
    "retweets": 10000,
    "replies": 5000,
    "views": 1000000,
    "created_at": "2024-01-15T10:30:00.000Z",
    "url": "https://x.com/elonmusk/status/1234567890",
    "is_retweet": false,
    "is_reply": false,
    "media": [{"type": "image", "url": "..."}],
    "hashtags": ["#tech"],
    "mentions": ["@OpenAI"],
    "scraped_at": "2024-01-15T12:00:00.000Z"
}
```

#### Profile Data

```json
{
    "name": "Elon Musk",
    "username": "elonmusk",
    "bio": "...",
    "location": "Austin, TX",
    "website": "tesla.com",
    "join_date": "Joined June 2009",
    "followers": "170M",
    "following": "500",
    "is_verified": true,
    "profile_image_url": "...",
    "url": "https://x.com/elonmusk",
    "scraped_at": "2024-01-15T12:00:00.000Z"
}
```

### Local Development

#### Prerequisites

- Python 3.9+
- pip

#### Setup

```bash
## Navigate to the actor directory
cd twitter-scraper-python

## Create virtual environment
python -m venv venv

## Activate (Windows)
.\venv\Scripts\activate

## Activate (Linux/Mac)
source venv/bin/activate

## Install dependencies
pip install -r requirements.txt

## Install Playwright browsers
playwright install chromium
```

#### Run Locally

```bash
## Using Apify CLI
apify run

## Or directly
python -m src.main
```

#### Test Input

Edit `apify_storage/key_value_stores/default/INPUT.json`:

```json
{
    "usernames": ["elonmusk"],
    "max_tweets": 10
}
```

### Deployment to Apify

```bash
## Login to Apify
apify login

## Push to Apify
apify push
```

### Limitations

- **Rate Limits**: Twitter may rate-limit after many requests
- **Login Walls**: Some content requires authentication
- **Dynamic Changes**: Twitter's DOM may change

### Tips

- Use **residential proxies** for better success rates
- Start with **small limits** to test
- Use **Apify Proxy** when deploying to Apify platform

### License

ISC License

# Actor input Schema

## `search_terms` (type: `array`):

List of search queries to find tweets (e.g., '#AI', 'bitcoin', 'OpenAI')

## `usernames` (type: `array`):

List of Twitter usernames to scrape tweets from (without @)

## `tweet_urls` (type: `array`):

Direct URLs to specific tweets to scrape

## `scrape_type` (type: `string`):

What type of data to scrape

## `max_tweets` (type: `integer`):

Maximum number of tweets to scrape per search/user

## `include_replies` (type: `boolean`):

Include reply tweets in results

## `include_retweets` (type: `boolean`):

Include retweets in results

## `min_likes` (type: `integer`):

Only include tweets with at least this many likes

## `min_retweets` (type: `integer`):

Only include tweets with at least this many retweets

## `proxy_configuration` (type: `object`):

Proxy settings for requests

## Actor input object example

```json
{
  "search_terms": [
    "#technology"
  ],
  "usernames": [
    "elonmusk"
  ],
  "scrape_type": "tweets",
  "max_tweets": 50,
  "include_replies": false,
  "include_retweets": true,
  "min_likes": 0,
  "min_retweets": 0,
  "proxy_configuration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "search_terms": [
        "#technology"
    ],
    "usernames": [
        "elonmusk"
    ],
    "proxy_configuration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ]
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("akshaynceo/x-scrapper-twitter-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "search_terms": ["#technology"],
    "usernames": ["elonmusk"],
    "proxy_configuration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
    },
}

# Run the Actor and wait for it to finish
run = client.actor("akshaynceo/x-scrapper-twitter-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "search_terms": [
    "#technology"
  ],
  "usernames": [
    "elonmusk"
  ],
  "proxy_configuration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}' |
apify call akshaynceo/x-scrapper-twitter-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,akshaynceo/x-scrapper-twitter-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/mguK4Fd8nAiN2hZg7/builds/GH6aFo9mH8edLTnVB/openapi.json
