https://github.com/hamidbyte/twitter-trending-hashtags-scraper-python
This Python script scrapes the trending topics from the website trends24.in and generates hashtags from the trends. It supports filtering for English-only trends and ensures that the generated hashtags fit within Twitter's character limits.
https://github.com/hamidbyte/twitter-trending-hashtags-scraper-python
hashtag hashtag-generator hashtag-scraper hashtags python python3 trending-hashtags trending-topics twitter x-com
Last synced: 5 months ago
JSON representation
This Python script scrapes the trending topics from the website trends24.in and generates hashtags from the trends. It supports filtering for English-only trends and ensures that the generated hashtags fit within Twitter's character limits.
- Host: GitHub
- URL: https://github.com/hamidbyte/twitter-trending-hashtags-scraper-python
- Owner: HamidByte
- Created: 2025-01-10T01:50:39.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-08T06:28:19.000Z (about 1 year ago)
- Last Synced: 2025-02-08T07:23:04.997Z (about 1 year ago)
- Topics: hashtag, hashtag-generator, hashtag-scraper, hashtags, python, python3, trending-hashtags, trending-topics, twitter, x-com
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Twitter Trending Topics/Hashtags Scraper
This Python script scrapes the trending topics from the website trends24.in and generates hashtags from the trends. It supports filtering for English-only trends and ensures that the generated hashtags fit within Twitter's character limits.
## Requirements
- Python 3.x
- Selenium
- BeautifulSoup
- WebDriver Manager
- Regular expressions (for filtering)
You can install the required packages using pip:
```bash
pip install selenium beautifulsoup4 webdriver-manager
```
## Usage
1. Run the script:
```bash
python t3_scraper.py
```
2. The script will:
- Open the trends24.in website.
- Accept the cookie consent (if prompted).
- Navigate to the "Table" section to gather trending topics.
- Extract the trending topics along with additional information such as rank, position, count, and duration.
- Optionally filter only English topics (if `ENGLISH_ONLY_REGEX` is set to `True`).
- Create and print hashtags based on the most popular trends while adhering to Twitter's 280-character limit.
## Configuration
- `HEADLESS_MODE`: Set to `True` to run in headless mode (without opening a browser window).
- `ENGLISH_ONLY_REGEX`: Set to `True` to filter for English-only trends based on regex patterns.
- `TWEET_MAX_CHARS`: The character limit for hashtags (default is 280).
## Creating a Standalone Executable
To create a standalone executable from the Python script using PyInstaller:
1. Install PyInstaller:
```bash
pip install pyinstaller
```
2. Navigate to the directory containing your script and run the following command:
```bash
pyinstaller --onefile t3_scraper.py
```
This will generate a standalone executable in the `dist` directory. You can run this executable without needing to install Python or any dependencies on the target machine.
## Executing the Script
On Linux, ensure that the generated executable is set as executable by running:
```bash
chmod +x dist/t3_scraper dist/run_scraper.sh
```
**Running the Script**
You can run the script in two ways:
Option 1: Right-click the `run_scraper.sh` file and select "Run as a Program" to execute it.
Option 2: Using the Terminal
- Open a terminal window.
- Navigate to the directory where the `run_scraper.sh` file is located.
- Run the following command:
```bash
./run_scraper.sh
```
This will execute the scraper by launching the executable.
## Notes
- Ensure you have the Chrome WebDriver installed. You can use the WebDriver Manager to automatically handle this.
- Adjust the sleep times if necessary based on your internet speed or website load time.