Skip to main content

An open source Python package CLI tool for scraping public X (Twitter) tweets using Playwright

Project description

twitterxscraper

An open source Python package CLI tool for scraping public X (Twitter) tweets using Playwright.

Why I Built

I built this because I wanted to understand how scraping actually works.

I wanted to deal with a modern site like X, where the page never fully settles, things keep loading in the background, and you can’t just wait for a simple page load event and hope for the best.

I also wanted to stop hardcoding values everywhere and start writing code that can be reused without opening files and changing strings every time. Passing inputs at runtime, handling limits properly, and structuring things like a real tool mattered to me.

More than anything, I wanted to build something small, real, and finished, not just another experiment that works once and gets abandoned.

What it can do

At a basic level, this scraper pulls public tweets from any username you give it. It loads the page properly, scrolls to fetch more tweets, and then extracts only the actual tweet text instead of all the surrounding UI noise.

It also grabs timestamps so the data is not just text without context. Once the scrape is done, everything is saved to a CSV file so you can inspect it, analyze it, or use it elsewhere.

Everything runs from the terminal. You pass the username, optionally pass a limit, and the scraper does the rest.

What it does not do

This scraper does not log into any accounts and it does not touch private profiles. It only works with what is already publicly visible on X.

There are no API keys involved and no attempt to pretend this is more stable than it really is. If X changes their layout in the future, some parts of this will need to be updated. That is just how scraping works.

This is scraping. Stuff breaks sometimes. That’s part of it.

Tech used

  • Python
  • Playwright
  • Pandas

I just used tools that get the job done.

Setup

Clone the repo.

git clone https://github.com/calchiwo/twitter-scraper.git
cd twitterxscraper

Install dependencies.

python -m pip install -r requirements.txt
python -m playwright install chromium

Usage

Run the example script and pass a username.

python examples.scrape_user.py elonmusk

With a custom limit.

python examples.scrape_user.py elonmusk 15

This creates a CSV file named after the username, for example elonmusk.csv.
CSV files are ignored by git and stay local.

Using it in your own code

You can also use it directly as a Python class.

from twitter_scraper.scraper import TwitterScraper

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

print(tweets)

Nothing runs on import. Also scraping only happens when you call the method.

Notes

X never becomes network idle, so this uses domcontentloaded.
Playwright launches a real browser.
The first run might feel slow. That’s normal.
If X changes their layout, selectors may need updates.

This is part of the game.

Disclaimer

This project is for educational and research purposes only.

Be responsible.
Respect platform rules.
Do not abuse it.

Final thoughts

If you are learning scraping, packaging, or just want to understand how things work under the hood, feel free to explore the code.

If it helps you, cool.

If it breaks, fix it!. That’s the fun part tbh.

Authour

Caleb Wodi GitHub

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.0.0.tar.gz (4.1 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.0.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for twitterxscraper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 044c3c8a9ef3869a1386d191243e1cc7cc8869fc258c35934cf7bed82b3199f8
MD5 e1e1831001f39118d4f16c655064ef06
BLAKE2b-256 17e8a2b5cb6221fea3d84bc5ece782398dab9d7026ebe5336c2f8e315557c2f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for twitterxscraper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f60916cb56722e3093dd40b4b38ba5c2f55837bf58caf4cc00c7bb00141ef09
MD5 bbe835441a5a7e741a6ca7f2c1b3e005
BLAKE2b-256 0578329d73ba0e08b7499095aabf850123d9c726d4dea3caebacf5e8769e029b

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