A Python script that uses the Twitter API (via Tweepy) to collect recent tweets for specified keywords, automatically handles rate limits, and saves results to CSV files. Perfect for researchers, cybersecurity analysts, and OSINT investigators.
- Collect multiple keywords in English
- Save results to keyword-specific CSV files
- Automatically waits when hitting Twitter API rate limits
- Secure API key storage via .env file
- Easy to customize keywords and settings
- Python 3.8+
- Tweepy library
- python-dotenv library
- Twitter Developer account with Bearer Token
-
Clone the repository or download the files: git clone https://github.com/ifyouknowyou/twitter_scraper.git cd twitter_scraper
-
Install required Python libraries: pip install -r requirements.txt
-
Create a file named
.envin the project folder. -
Add your Twitter Bearer Token in the
.envfile: BEARER_TOKEN=your_twitter_bearer_token_here -
Make sure
.envis NOT uploaded to GitHub (it's in .gitignore).
-
Run the scraper script: python scraper.py
-
The script will:
- Collect tweets for the keywords specified in
scraper.py - Save results in CSV files (one per keyword)
- Automatically wait if rate limits are reached
- Collect tweets for the keywords specified in
-
To stop the scraper: Press CTRL + C
-
To run in the background on Linux: nohup python scraper.py &
-
You can add or change keywords by editing the
KEYWORDSlist inscraper.py. -
CSV files are appended each run, so old data is preserved.