Wednesday, August 7, 2024

A python script to scrape today's trending Instagram hashtags

Scrape Trending Hashtags

Scrape Trending Hashtags

Here's a simple Python script using the requests and BeautifulSoup libraries to scrape the top 30 trending hashtags from a website. You can run this script in Termux:

import requests
from bs4 import BeautifulSoup

def get_trending_hashtags(url):
    response = requests.get(url)
    soup = BeautifulSoup(response.text, 'html.parser')
    
    hashtags = []
    for tag in soup.find_all('a', class_='hashtag'):
        hashtags.append(tag.text)
        if len(hashtags) >= 30:
            break
    
    return hashtags

if __name__ == "__main__":
    url = 'https://example.com/trending-hashtags'  
    # Replace with the actual URL
    trending_hashtags = get_trending_hashtags(url)
    for i, hashtag in enumerate(trending_hashtags, 1):
        print(f"{i}. {hashtag}")

Steps to Run the Script in Termux:

  1. Install Python and Required Libraries:
    pkg install python
    pip install requests beautifulsoup4
  2. Save the Script:

    Save the above script in a file, for example, scrape_hashtags.py.

  3. Run the Script:
    python scrape_hashtags.py

Note:

  • Replace 'https://example.com/trending-hashtags' with the actual URL of the website you want to scrape.
  • Ensure the website allows web scraping by checking its robots.txt file or terms of service.

No comments:

Post a Comment