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.
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.
- 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
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.
pip install twitterxscraper
python -m playwright install chromiumgit clone https://github.com/calchiwo/twitterxscraper.git
cd twitterxscraperInstall dependencies.
python -m pip install -e .
python -m playwright install chromiumtwitterxscraper <username>Example:
twitterxscraper elonmuskThis creates a CSV file named after the username: <username>.csv.
twitterxscraper <username> --limit 15Example:
twitterxscraper elonmusk --limit 15twitterxscraper <username> --headfulYou can also run it using:
python -m twitterxscraper <username>The scraper exports a CSV file with the following columns:
- username
- text
- timestamp
- 0 → Successful scrape
- 1 → No tweets found or validation error
You can also run directly as a Python class.
from twitterxscraper import TwitterScraper
scraper = TwitterScraper()
tweets = scraper.scrape_user("<username>", limit=10)
print(tweets)- Python 3.8+
- Chromium browser installed via
python -m playwright install chromium
- 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
- Python
- Playwright
- Pandas
- Rich (CLI formatting)
This project is intended for educational and research purposes only.
Respect platform terms of service and applicable laws. Use responsibly.
MIT