Thursday, May 8, 2025

Web Scraping and Data Extraction - Website Change Tracker

 


Notes:

  • Problem Solved: Monitors a webpage for any HTML/textual changes over time.

  • Customization Benefits: Set up alerts or track competitor website updates.

  • Further Adoption: Integrate with Slack/email APIs to send alerts.

Python Code:


import hashlib
import requests
import time

def get_page_hash(url):
    response = requests.get(url)
    return hashlib.sha256(response.text.encode()).hexdigest()

def track_changes(url, interval=60):
    old_hash = get_page_hash(url)
    print("Monitoring started...")
    while True:
        time.sleep(interval)
        new_hash = get_page_hash(url)
        if new_hash != old_hash:
            print("Website content changed!")
            break
        else:
            print("No change detected...")

# Example usage
# track_changes("https://example.com", interval=300)

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...