Python Python Free

Python: Monitor a Website and Alert on Change

Watch a web page with Python and get an alert when its text changes — track prices, results and announcements.

23 lines · Updated Nov 26, 2026

Preview of Python: Monitor a Website and Alert on Change
python-website-change-monitor.py
import hashlib
import time
import requests

def page_hash(url):
    response = requests.get(url, headers={
        "User-Agent": "ChangeMonitor/1.0 (learning project)",
    }, timeout=15)
    response.raise_for_status()
    return hashlib.sha256(response.text.encode()).hexdigest()

if __name__ == "__main__":
    url = "https://example.com/results"
    last = page_hash(url)
    print("Watching", url)
    while True:
        time.sleep(300)  # check every 5 minutes
        current = page_hash(url)
        if current != last:
            print("PAGE CHANGED:", url)
            last = current
        else:
            print("No change.")

About this snippet

Waiting for a results page, a job listing, a product restock or a government notice? Instead of refreshing it every hour, let Python do it. This snippet checks a web page on a schedule, compares it with the previous version and alerts you when the content changes.

How it works

  1. It downloads the page with an HTTP request.
  2. It extracts the part you care about (or the whole text) and creates a hash — a short fingerprint of the content.
  3. It compares the hash with the one saved from the last run. If they differ, the page changed, so it sends an alert and saves the new hash.

How to use it

  1. Install the requirements (typically requests, and beautifulsoup4 if you target part of a page).
  2. Set the URL and, ideally, a CSS selector for just the section you want to watch — otherwise ads, dates and counters trigger false alarms.
  3. Schedule it with cron or Task Scheduler every 15–60 minutes.
  4. Connect alerts to Telegram or email — see the Telegram bot snippet.

Be a polite bot

  • Check the site's terms and robots.txt.
  • Do not check more often than you need; once an hour is plenty for most pages.
  • Set a timeout and a clear User-Agent.

Common problems

  • Alerts on every run: the page contains changing elements like timestamps. Monitor a specific element instead.
  • Empty content: the page loads data with JavaScript. Look for the underlying API request in DevTools, or use a headless browser like Playwright.

FAQ

Can it monitor prices? Yes — extract the price element and compare numbers instead of hashes.

Related: 10 Python automation projects · Retry with backoff

How to install

Run the script and leave it running, or schedule it with cron. Change the URL and the sleep time to suit the page. Add the Telegram snippet from this collection to get the alert on your phone.

Share this snippet

See all
Chat with us