Skip to main content

TwitterXScraper

A Python CLI tool for scraping public X (Twitter) profile tweets using Playwright and exporting structured results to a CSV file without requiring API keys.

PyPI Version PyPI Downloads Python License: MIT

Demo video

Why this exists

I needed a simple way to pull public tweets from X without using the official API, managing authentication tokens, or dealing with rate limits.

So I wrote this CLI tool that accepts a username, opens a Chromium browser using Playwright, scrolls a profile dynamically, extracts tweet text and timestamps, and exports everything into a CSV file.

Features

  • Scrape public tweets from any username
  • Automatically scroll to load more tweets
  • Extract clean tweet text
  • Extract timestamps
  • Save results to CSV
  • Headless and headful modes
  • Configurable tweet limit
  • No API keys required
  • No authentication

How It Works

The scraper launches a Chromium browser using Playwright, navigates to a public X profile, waits for dynamic content to load, scrolls to trigger additional tweet loading, and extracts structured data from the DOM.

Installation

pip install twitterxscraper
python -m playwright install chromium

Clone this repository

git clone https://github.com/calchiwo/twitterxscraper.git
cd twitterxscraper

Install dependencies.

python -m pip install -e .
python -m playwright install chromium

Usage

Run the CLI and pass a username:

twitterxscraper <username>

Example:

twitterxscraper elonmusk

This creates a CSV file named after the username: <username>.csv.

Set tweet limit:

twitterxscraper <username> --limit 15

Example:

twitterxscraper elonmusk --limit 15

Run in a visible browser mode (debugging)

twitterxscraper <username> --headful

Run as a module

You can also run it using:

python -m twitterxscraper <username>

Show installed version

Prints the installed package version.

twitterxscraper --version

Output

The scraper exports a CSV file with the following columns:

  • username
  • text
  • timestamp

Exit Codes

  • 0 → Successful scrape
  • 1 → No tweets found or validation error

Using it in your own code

You can also run directly as a Python class.

from twitterxscraper import TwitterScraper

scraper = TwitterScraper()
tweets = scraper.scrape_user("<username>", limit=10)

print(tweets)

Requirements

  • Python 3.8+
  • Chromium browser installed via python -m playwright install chromium
  • macOS, Linux, and Windows

Limitations

  • Only works on public profiles
  • No login support
  • No private accounts
  • May break if X changes layout
  • Uses a Chromium browser with Playwright
  • X is a dynamic platform so layout changes may require selector updates
  • Scraping behavior may vary depending on network conditions and X's anti-bot mechanisms

Tech stack used

  • Python
  • Playwright
  • Pandas
  • Rich (CLI formatting)

Disclaimer

This project is intended for educational and research purposes only.

Respect platform terms of service and applicable laws. Use responsibly.

License

MIT

Author

Caleb Wodi

Metadata

Release files for twitterxscraper 1.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for twitterxscraper 1.1.5
File Size Uploaded
twitterxscraper-1.1.5.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for twitterxscraper 1.1.5
File Interpreter ABI Platform
twitterxscraper-1.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 15.0 kB

Release files / twitterxscraper-1.1.5.tar.gz

Download URL twitterxscraper-1.1.5.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9ebaaebcf61a329a458d9fcc47d27e872addac1388a6faf60565b7ad695cce1c
BLAKE2b-256 checksum
How to use checksums
8f9d58ca3cfc922a7b4061c0d1e1d63bbf0c3704cc4b58d1c7137b32f7685913
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / twitterxscraper-1.1.5-py3-none-any.whl

Download URL twitterxscraper-1.1.5-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17e573d63ccc60a9a260e1e4e22d8182fcbea2ef21dc7f91bc6e8c758190463c
BLAKE2b-256 checksum
How to use checksums
32c7599fc98de9605a83fe6efd97103160e9d1cd5f6238dd79dec07a4a57f704
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

1.1.5 This release

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page