Skip to main content

A CLI tool for scraping Twitter trends and tweets.

Project description

Twitter Scraper CLI

A Python package to scrape Twitter trends and tweets using Selenium. It provides a command-line interface (CLI) for easy use and doesnot require any twitter api.

Features

  • Scrape trending topics from Twitter.
  • Scrape tweets for specific trends.
  • Specify the fields you want to scrape (e.g., tweet text, images, likes).

Installation

To install the package, run:

pip install twitter-cli-scraper

Usage

The Twitter Scraper CLI can be used via the command line after installation. Below are some examples of usage:

1. Scraping Twitter Trends

To scrape the latest trends from Twitter, use the following command:

twitter-scraper --username your_twitter_username --password your_twitter_password --action scrape_trends

This command will log in to Twitter using your credentials, scrape the trending topics, and save the data in an Excel file called trends.xlsx.

2. Scraping Tweets for a Specific Trend

If you want to scrape tweets related to a specific trend, you can do the following:

twitter-scraper --username your_twitter_username --password your_twitter_password --action scrape_tweets --trend "trend_name" --fields tweets images likes

For example, to scrape tweets for the trend "WorldCup2024" and extract both the tweet text and images, you would run:

twitter-scraper --username your_twitter_username --password your_twitter_password --action scrape_tweets --trend "WorldCup2024" --fields tweets images

This will scrape tweets containing the term "WorldCup2024" and save the results in an Excel file called tweets.xlsx.

3. Available Fields to Scrape

When scraping tweets, you can specify which fields you want to extract by using the --fields option. You can choose from the following fields:

  • tweets: Scrapes the tweet text.
  • images: Scrapes any image URLs in the tweet.
  • likes: Scrapes the number of likes.

If no fields are specified, the tool will default to scraping tweet text (tweets).

4. Example Commands

Scrape Only Trends:

twitter-scraper --username your_username --password your_password --action scrape_trends

Scrape Tweets for a Trend:

twitter-scraper --username your_username --password your_password --action scrape_tweets --trend "Olympics" --fields tweets likes

This command will scrape tweets related to the "Olympics" trend and include tweet text and like counts in the output.

Command Line Arguments

  • --username: Your Twitter username.
  • --password: Your Twitter password.
  • --action: The action to perform (scrape_trends or scrape_tweets).
  • --trend: The name of the trend to search for (required for scrape_tweets action).
  • --fields: A list of fields to scrape (e.g., tweets, images, likes). Defaults to tweets.

Output

  • Trends : Saved as trends.xlsx containing trending topics and related keywords.
  • Tweets : Saved as tweets.xlsx containing the scraped data based on the specified fields (e.g., tweet text, images, likes).

Error Handling

If any error occurs during the scraping process, the scraper will attempt to handle it gracefully and log the error for further inspection.

Contributing

Contributions are welcome! If you find any bugs or want to request a new feature, feel free to open an issue on the Github repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Disclaimer : This tool is for educational purposes only. Please ensure you comply with Twitter's Terms of Service when using this scraper.

Breakdown:

  • Usage Commands: Added clear examples for both scraping trends and tweets.
  • Fields Explanation: Provided options for which fields users can scrape.
  • Example Section: Showcased sample command-line usage.

This should cover all aspects of usage, including installation, examples, and command-line arguments. Let me know if you need anything else!

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

twitter-cli-scraper-0.1.2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twitter_cli_scraper-0.1.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file twitter-cli-scraper-0.1.2.tar.gz.

File metadata

  • Download URL: twitter-cli-scraper-0.1.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for twitter-cli-scraper-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3d52d12badbeadb75f7f673eea1ba6e12b90d34a45dda3e2ac8e3514b948cec1
MD5 327c23d2ed4dfbd2b44391b075af8e81
BLAKE2b-256 a6cd72f3ff490e61f7a3f4f7bd847637c4c464fbdbeab72b37f44279c7f0d823

See more details on using hashes here.

File details

Details for the file twitter_cli_scraper-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for twitter_cli_scraper-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 709bd322f4cb1acbfff527256ef4131d51a9ec7993992d81a9ec40dba0700cca
MD5 56cd957127dadde99fed4ec78c024328
BLAKE2b-256 5eb2b665af60fe476f42e17cd78da7e695b67026ab7cb7dc4c89df5ff29ca9ef

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