# Twitter Profile Scraper (`hamdo/twitter-profile-scraper`) Actor

Twitter/X Profile Scraper
A fast and reliable Actor designed to fetch essential Twitter/X profile information with minimal input. Simply provide a list of usernames (without the @), and the Actor will automatically collect key profile details with high accuracy.

- **URL**: https://apify.com/hamdo/twitter-profile-scraper.md
- **Developed by:** [Mahmoud Alhamdo](https://apify.com/hamdo) (community)
- **Categories:** Automation, E-commerce, Social media
- **Stats:** 16 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.10 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Twitter/X Profile Scraper

A fast and efficient Apify Actor built with Python and Playwright to scrape Twitter/X user profile information.

### 🚀 Features

- **Fast scraping** using Playwright for reliable data extraction
- **Simple input** - just provide usernames (without @)
- **Extracts essential profile data**:
  - Name
  - Bio/Description
  - Location
- **Handles dynamic content** - waits for page elements to load properly
- **Error handling** - continues processing even if one profile fails

### 📋 Input

The Actor accepts a list of Twitter/X usernames:

```json
{
  "usernames": ["LG1904", "username2", "username3"]
}
````

**Note:** Usernames should be provided without the `@` symbol.

### 📤 Output

The Actor outputs profile data in the following format:

```json
{
  "name": "LG",
  "bio": "مهتم بالعملات الرقمية والاستثمار | أتابع أحدث الأخبار وأفضل الفرص الاستثمارية | Focused on crypto investments and market opportunities. Snapchat : LG055555",
  "location": "الرياض"
}
```

Each profile is saved as a separate item in the dataset.

### 🛠️ Built With

- **[Apify SDK](https://docs.apify.com/sdk/python/)** for Python - toolkit for building Apify Actors
- **[Playwright](https://playwright.dev/python/)** - browser automation library for reliable web scraping
- **[Input schema](https://docs.apify.com/platform/actors/development/input-schema)** - validates and defines Actor input
- **[Dataset](https://docs.apify.com/platform/storage/dataset)** - stores structured output data

### 🚦 Getting Started

#### Prerequisites

- Python 3.8+
- [Apify CLI](https://docs.apify.com/cli) installed
- Playwright browsers installed

#### Installation

1. Clone or download this Actor

2. Install dependencies:
   ```bash
   pip install -r requirements.txt
   ```

3. Install Playwright browsers:
   ```bash
   playwright install --with-deps
   ```

#### Running Locally

1. Update the input file `storage/key_value_stores/default/INPUT.json`:
   ```json
   {
     "usernames": ["LG1904"]
   }
   ```

2. Run the Actor:
   ```bash
   apify run
   ```

3. Check the results in `storage/datasets/default/`

### 📦 Deploy to Apify Platform

#### Option 1: Push from Local Machine

1. Log in to Apify:
   ```bash
   apify login
   ```
   You'll need your [Apify API Token](https://console.apify.com/account/integrations)

2. Deploy the Actor:
   ```bash
   apify push
   ```

3. Find your Actor in [Actors -> My Actors](https://console.apify.com/actors?tab=my)

#### Option 2: Connect Git Repository

1. Push your code to a Git repository (GitHub, GitLab, etc.)

2. Go to [Actor creation page](https://console.apify.com/actors/new)

3. Click **Link Git Repository** and follow the instructions

### 📊 How It Works

1. The Actor reads usernames from the input
2. For each username, it navigates to `https://x.com/{username}`
3. Waits for the page to load and dynamic content to render
4. Extracts profile information using CSS selectors:
   - **Name**: from `div[data-testid="UserName"]`
   - **Bio**: from `div[data-testid="UserDescription"] span`
   - **Location**: from `span[data-testid="UserLocation"] span span`
5. Saves the extracted data to the dataset

### ⚙️ Configuration

The Actor uses the following settings:

- **Timeout**: 60 seconds for page load
- **Wait strategy**: Uses `load` event (more reliable than `networkidle` for Twitter/X)
- **Additional wait**: 3 seconds for dynamic content to render
- **User agent**: Standard Chrome user agent to avoid detection

### 🔧 Troubleshooting

#### Timeout Errors

If you encounter timeout errors, the page might be loading slowly. The Actor already uses optimized timeouts, but you can adjust them in `src/main.py` if needed.

#### Missing Data

If some fields are missing (null), it might mean:

- The profile doesn't have that information
- The page structure changed (Twitter/X updates their HTML)
- The page didn't load completely

#### Rate Limiting

Twitter/X may rate limit requests if you scrape too many profiles too quickly. Consider adding delays between requests if needed.

### 📚 Resources

- [Apify SDK for Python documentation](https://docs.apify.com/sdk/python)
- [Playwright Python documentation](https://playwright.dev/python/)
- [Apify Platform documentation](https://docs.apify.com/platform)
- [Apify Academy](https://docs.apify.com/academy/python)
- [Join Apify Discord community](https://discord.com/invite/jyEM2PRvMU)

### 📝 License

This Actor is provided as-is. Make sure to comply with Twitter/X Terms of Service when using this scraper.

### 🤝 Contributing

Feel free to submit issues or pull requests to improve this Actor!

### 📧 Support

For issues and questions:

- Check [Apify documentation](https://docs.apify.com)
- Join [Apify Discord](https://discord.com/invite/jyEM2PRvMU)
- Contact Apify support through the platform

***

**Note:** This Actor is for educational and legitimate use cases only. Always respect website terms of service and rate limits.

# Actor input Schema

## `user_id` (type: `string`):

Twitter/X user ID to scrape. Example: '2622731' or '1842452712555716608'. Can also extract ID from URL like 'https://twitter.com/i/user/2622731'

## Actor input object example

```json
{}
```

# Actor output Schema

## `overview` (type: `string`):

No description

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("hamdo/twitter-profile-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 = {}

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

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

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

```

## CLI example

```bash
echo '{}' |
apify call hamdo/twitter-profile-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=hamdo/twitter-profile-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Twitter Profile Scraper",
        "description": "Twitter/X Profile Scraper\nA fast and reliable Actor designed to fetch essential Twitter/X profile information with minimal input. Simply provide a list of usernames (without the @), and the Actor will automatically collect key profile details with high accuracy.",
        "version": "1.0",
        "x-build-id": "rt0eAyOfLak4BXwv5"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/hamdo~twitter-profile-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-hamdo-twitter-profile-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/hamdo~twitter-profile-scraper/runs": {
            "post": {
                "operationId": "runs-sync-hamdo-twitter-profile-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/hamdo~twitter-profile-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-hamdo-twitter-profile-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "user_id"
                ],
                "properties": {
                    "user_id": {
                        "title": "User ID",
                        "type": "string",
                        "description": "Twitter/X user ID to scrape. Example: '2622731' or '1842452712555716608'. Can also extract ID from URL like 'https://twitter.com/i/user/2622731'"
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
