# X (Twitter) User Scraper (`lumen_limitless/x-crawler`) Actor

This project is a web scraper designed to extract user data and tweets from X (formerly known as Twitter) using Crawlee and Playwright.

- **URL**: https://apify.com/lumen\_limitless/x-crawler.md
- **Developed by:** [Lumen Limitless](https://apify.com/lumen_limitless) (community)
- **Categories:** Social media
- **Stats:** 304 total users, 1 monthly users, 100.0% runs succeeded, 4 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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

## X (Twitter) Crawler

[![Website Content Crawler Actor](https://apify.com/actor-badge?actor=lumen_limitless/x-crawler)](https://apify.com/apify/x-crawler)

This project is a web scraper designed to extract user data and tweets from X (formerly known as Twitter) using Crawlee and Playwright.

### Purpose

The main purpose of this scraper is to:

1. Navigate to a specified X user profile
2. Extract user information
3. Collect 100 most liked tweets from the user's timeline

This tool can be useful for various applications, such as:

- Social media analysis
- User behavior research
- Content aggregation
- Sentiment analysis

### Features

- Utilizes Playwright for browser automation
- Implements Crawlee for efficient web crawling
- Extracts user profile data
- Collects recent tweets from the user's timeline
- Handles X's dynamic content loading

### Usage

1. Set the target user's profile URL in the `startUrls` array in the input configuration.
2. Adjust the `maxRequestsPerCrawl` value to limit the number of requests if needed.
3. Run the scraper to collect data.

### Output

The scraper outputs two main types of data:

1. User information
2. Recent tweets from the user's timeline

The collected data is structured and can be easily processed for further analysis or integration into other systems.

### Output Example

Here's an example of the structured output you can expect from this scraper:

#### User Object

```json
"user": {
"__typename": "User",
"id": "VXNlcjo0NDE5NjM5Nw==",
"rest_id": "44196397",
"affiliates_highlighted_label": {
"label": {
"url": {
"url": "https://twitter.com/X",
"urlType": "DeepLink"
},
"badge": {
"url": "https://pbs.twimg.com/profile_images/1683899100922511378/5lY42eHs_bigger.jpg"
},
"description": "X",
"userLabelType": "BusinessLabel",
"userLabelDisplayType": "Badge"
}
},
"is_blue_verified": true,
"profile_image_shape": "Circle",
"legacy": {
"created_at": "Tue Jun 02 20:12:29 +0000 2009",
"default_profile": false,
"default_profile_image": false,
"description": "",
"entities": {
"description": {
"urls": []
}
},
"fast_followers_count": 0,
"favourites_count": 60807,
"followers_count": 189827332,
"friends_count": 662,
"has_custom_timelines": true,
"is_translator": false,
"listed_count": 152087,
"location": "",
"media_count": 2308,
"name": "Elon Musk",
"normal_followers_count": 189827332,
"pinned_tweet_ids_str": [
"1813310196506349995"
],
"possibly_sensitive": false,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/44196397/1690621312",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/1780044485541699584/p78MCn3B_normal.jpg",
"profile_interstitial_type": "",
"screen_name": "elonmusk",
"statuses_count": 47242,
"translator_type": "none",
"verified": false,
"withheld_in_countries": []
},
"professional": {
"rest_id": "1679729435447275522",
"professional_type": "Creator",
"category": []
},
"tipjar_settings": {
"is_enabled": false,
"bandcamp_handle": "",
"bitcoin_handle": "",
"cash_app_handle": "",
"ethereum_handle": "",
"gofundme_handle": "",
"patreon_handle": "",
"pay_pal_handle": "",
"venmo_handle": ""
},
"legacy_extended_profile": {},
"is_profile_translatable": false,
"has_hidden_subscriptions_on_profile": false,
"verification_info": {
"is_identity_verified": false,
"reason": {
"description": {
"text": "This account is verified because it's an affiliate of @X on X. Learn more",
"entities": [
{
"from_index": 54,
"to_index": 56,
"ref": {
"url": "https://twitter.com/X",
"url_type": "ExternalUrl"
}
},
{
"from_index": 63,
"to_index": 73,
"ref": {
"url": "https://help.twitter.com/en/rules-and-policies/profile-labels",
"url_type": "ExternalUrl"
}
}
]
},
"verified_since_msec": "-156836000000000",
"override_verified_year": -3000
}
},
"highlights_info": {
"can_highlight_tweets": true,
"highlighted_tweets": "265"
},
"user_seed_tweet_count": 0,
"business_account": {},
"creator_subscriptions_count": 151
},
```

#### Tweet Object

```json
{
"__typename": "Tweet",
"rest_id": "1519480761749016577",
"unmention_data": {},
"is_translatable": false,
"views": {
"state": "Enabled"
},
"source": "<a href=\"http://twitter.com/download/iphone/" rel=\"nofollow\">Twitter for iPhone</a>",
"legacy": {
"bookmark_count": 21256,
"bookmarked": false,
"created_at": "Thu Apr 28 00:56:58 +0000 2022",
"conversation_id_str": "1519480761749016577",
"display_text_range": [
0,
52
],
"entities": {
"hashtags": [],
"symbols": [],
"timestamps": [],
"urls": [],
"user_mentions": []
},
"favorite_count": 4468299,
"favorited": false,
"full_text": "Next I’m buying Coca-Cola to put the cocaine back in",
"is_quote_status": false,
"lang": "en",
"quote_count": 166677,
"reply_count": 182762,
"retweet_count": 625073,
"retweeted": false,
"user_id_str": "44196397",
"id_str": "1519480761749016577"
},
"quick_promote_eligibility": {
"eligibility": "IneligibleUserUnauthorized"
}
},
```

### Note

Please ensure you comply with X's terms of service and respect rate limits when using this scraper.

# Actor input Schema

## `startUrls` (type: `array`):

URLs to start with.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://x.com/elonmusk"
    }
  ]
}
```

# 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 = {
    "startUrls": [
        {
            "url": "https://x.com/elonmusk"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("lumen_limitless/x-crawler").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 = { "startUrls": [{ "url": "https://x.com/elonmusk" }] }

# Run the Actor and wait for it to finish
run = client.actor("lumen_limitless/x-crawler").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 '{
  "startUrls": [
    {
      "url": "https://x.com/elonmusk"
    }
  ]
}' |
apify call lumen_limitless/x-crawler --silent --output-dataset

```

## MCP server setup

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

```

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/wRUGRj7NFs528zQdv/builds/vjexMMvbFcHsH3q7q/openapi.json
