Skip to main content

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.

Project description

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

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 stabilize, 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>

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twitterxscraper-1.1.4.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twitterxscraper-1.1.4-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file twitterxscraper-1.1.4.tar.gz.

File metadata

  • Download URL: twitterxscraper-1.1.4.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for twitterxscraper-1.1.4.tar.gz
Algorithm Hash digest
SHA256 00a416540e7de0029e9330d2b5687de9792f9f3d54740e79dd35d3cc887af7ae
MD5 5d197d9c43613a6c0189f9272d6a6791
BLAKE2b-256 d62dc7611d31a3346e443a94e94e00c0e17f340ab07016b0b1c3691f316aa221

See more details on using hashes here.

File details

Details for the file twitterxscraper-1.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for twitterxscraper-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c84937606cc1765269b2cd79d97f515aeaa7efc0ea9f9507c6dc183beb8d9a31
MD5 bb3fec1730dae6d37be6ec9c27e7d4c8
BLAKE2b-256 9b59f2dfb9249979fcbb7214c1c2650c5bb73faeb7b7234bfc9d8bae7a45e388

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page