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.
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file twitterxscraper-1.1.5.tar.gz.
File metadata
- Download URL: twitterxscraper-1.1.5.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ebaaebcf61a329a458d9fcc47d27e872addac1388a6faf60565b7ad695cce1c
|
|
| MD5 |
8e85c2eb38eadf6a4cca47f6dcc22d5b
|
|
| BLAKE2b-256 |
8f9d58ca3cfc922a7b4061c0d1e1d63bbf0c3704cc4b58d1c7137b32f7685913
|
File details
Details for the file twitterxscraper-1.1.5-py3-none-any.whl.
File metadata
- Download URL: twitterxscraper-1.1.5-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17e573d63ccc60a9a260e1e4e22d8182fcbea2ef21dc7f91bc6e8c758190463c
|
|
| MD5 |
5ac0023de33023c2dce543564af5c428
|
|
| BLAKE2b-256 |
32c7599fc98de9605a83fe6efd97103160e9d1cd5f6238dd79dec07a4a57f704
|