Skip to main content

A Python CLI tool for scraping public X (Twitter) profile tweets using Playwright.

Project description

TwitterXScraper

A Lightweight Python tool for scraping public X (Twitter) tweets using Playwright.

I needed a simple way to pull public tweets from X without touching the API, dealing with tokens, or waiting on rate limits

So I wrote this CLI tool that asks for username, opens a Chromium browser with Playwright, scrolls a profile, grabs tweet text and timestamps, and dumps everything into a CSV.

PyPI: https://pypi.org/project/twitterxscraper

Features

  • Scrape public tweets from any username
  • Automatically scroll to load more tweets
  • Extract tweet text
  • Extract tweet timestamps
  • Save results to CSv
  • Works in the terminal
  • Installed with pip

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

How it use

Run the CLI and pass a username:

python twitterxscraper elonmusk

With a custom limit:

python twitterxscraper elonmusk --limit 15

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

Using it in your own code

You can also run it as a module directly as a Python class.

from twitterxscraper import TwitterScraper

scraper = TwitterScraper()
tweets = scraper.scrape_user("elonmusk", limit=10)

print(tweets)

Limitations

  • Only works on public profiles
  • No login support
  • No private acconts
  • Breaks if X layout changes
  • Uses a Chromium browser with Playwright

This is scraping. Layout changes can

Tech stack used

  • Python
  • Playwright
  • Pandas

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.3.tar.gz (5.7 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.3-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: twitterxscraper-1.1.3.tar.gz
  • Upload date:
  • Size: 5.7 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.3.tar.gz
Algorithm Hash digest
SHA256 27c73ed77222955042a1a76dc201b7aac33001fb9bf5ee0add5a50b33a011c63
MD5 e7fec60e00a6cc67f5a0196865baca06
BLAKE2b-256 e2f3d8be41be76901bb6ea6b85da65333e608d5563f3cb29ee5108fafc28977c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for twitterxscraper-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3b19b0938194a07ae826e88c93836a161a0e14471b09e99554bfdf048141f51e
MD5 d4e43c55b5ac263771f8bcad1a3e7d23
BLAKE2b-256 9d2bfb035cce50fd1c048e12833a8dfcf40560f0ab40a356efd26153dd5ccd6b

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