Web Monitoring with Python: Get Alerts When Prices Drop or Stock Returns

The most time-consuming part of online shopping isn't paying — it's refreshing the page over and over to see whether an item has dropped in price or come back in stock. With a dozen lines of Python, you can build a small "page watcher" that checks the page for you on a schedule and tells you the moment something changes. Here's how, line by line.

The idea: three steps

The whole thing is simple and breaks into three steps:

  1. Use requests to fetch the page's raw HTML
  2. Look for the phrase you care about — "in stock", or the price itself
  3. Use time.sleep to check again after a fixed interval, and only alert you when the state flips

Full code

Create a new file called watch.py and paste in the code below:

import requests import time URL = "https://example.com/product/12345" KEYWORD = "in stock" # the phrase you're watching for CHECK_EVERY = 300 # check every 5 minutes (300 seconds) def check(): r = requests.get(URL, timeout=10) return KEYWORD in r.text last = check() print("Watching... initial state:", "in stock" if last else "out of stock") while True: time.sleep(CHECK_EVERY) now = check() if now != last: msg = "✅ Back in stock!" if now else "❌ Out of stock again" print(msg, "→", URL) last = now

Line by line

  • requests.get(URL) — fetches the page's content, just like opening it in a browser.
  • r.text — the page's entire HTML as one big block of text.
  • KEYWORD in r.text — checks whether your phrase appears, returning True or False.
  • time.sleep(300) — waits 300 seconds before the next check, so you're not hammering the site.
  • The final if — only prints an alert when the state changes (out of stock → in stock), so it won't nag you every five minutes.

Going further: track an actual price

Checking for a word is coarse. If you want to know the exact price, use re (regular expressions) to pull the number out of the HTML and compare it with last time — that way you'll notice even a one-dollar drop.

Also, print only shows text on screen. To get the alert when you're away from the computer, swap it for an email or WhatsApp notification — our earlier "Automate Emails with Python" post shows exactly how, just plug it in.

Three cautions

  • Don't check too often — every 5 to 15 minutes is plenty. Checking too frequently adds load to the site and can get your IP blocked.
  • Respect the site's terms — only watch public pages, and read robots.txt and the terms before scraping at scale or for business.
  • Never watch login-gated pages — those involve privacy and aren't meant for this.

Summary

This Python tutorial summary: A dozen lines of code save you the daily F5 grind. Page watching is just one use — with the same pattern you can monitor your own site's uptime, a competitor's new arrivals, or when some data gets updated. The world of automation is wide open, and it starts with one small script.