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.
- Python 3.x
- Selenium
- BeautifulSoup
- WebDriver Manager
- Regular expressions (for filtering)
You can install the required packages using pip:
pip install selenium beautifulsoup4 webdriver-manager- Run the script:
python t3_scraper.py- 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_REGEXis set toTrue). - Create and print hashtags based on the most popular trends while adhering to Twitter's 280-character limit.
HEADLESS_MODE: Set toTrueto run in headless mode (without opening a browser window).ENGLISH_ONLY_REGEX: Set toTrueto filter for English-only trends based on regex patterns.TWEET_MAX_CHARS: The character limit for hashtags (default is 280).
To create a standalone executable from the Python script using PyInstaller:
- Install PyInstaller:
pip install pyinstaller- Navigate to the directory containing your script and run the following command:
pyinstaller --onefile t3_scraper.pyThis 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.
On Linux, ensure that the generated executable is set as executable by running:
chmod +x dist/t3_scraper dist/run_scraper.shRunning 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.shfile is located. - Run the following command:
./run_scraper.shThis will execute the scraper by launching the executable.
- 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.