Thursday, May 8, 2025

Web Scraping and Data Extraction - Social Media Hashtag Monitor

 


Notes:

  • Problem Solved: Scrapes Twitter for real-time hashtag mentions.

  • Customization Benefits: Track campaigns, analyze sentiment, or discover influencers.

  • Further Adoption: Store in a database, analyze sentiment, or trigger alerts.

Python Code:


import snscrape.modules.twitter as sntwitter

def get_tweets_by_hashtag(hashtag, max_tweets=50):
    tweets = []
    for i, tweet in enumerate(sntwitter.TwitterHashtagScraper(hashtag).get_items()):
        if i >= max_tweets:
            break
        tweets.append({'user': tweet.user.username, 'content': tweet.content})
    return tweets

# Example usage
tweets = get_tweets_by_hashtag("AI")
for t in tweets[:5]:
    print(f"{t['user']}: {t['content'][:80]}")


No comments:

Post a Comment

IoT (Internet of Things) Automation - Smart Energy Usage Tracker

  Notes: Problem Solved: Logs and analyzes power usage from smart meters. Customization Benefits: Track per-device energy and set ale...