Needed to track changes on a handful of web pages for a project last month. Nothing fancy — just know when content on specific URLs changes. Ended up building a quick pipeline that I figured might be useful to share.
The basic idea
Fetch page, hash the content, compare to previous hash, notify if different. Classic.
import hashlib
import requests
import json
from pathlib import Path
URLS = [
'https://example.com/pricing',
'https://example.com/features',
]
STATE_FILE = Path('page_states.json')
def load_state():
if STATE_FILE.exists():
return json.loads(STATE_FILE.read_text())
return {}
def save_state(state):
STATE_FILE.write_text(json.dumps(state, indent=2))
def get_page_hash(url):
resp = requests.get(url, timeout=30)
return hashlib.sha256(resp.text.encode()).hexdigest()
Simple enough. Run it on a cron, done.
Except not really.
The problems you hit immediately
Dynamic content. Most modern pages include timestamps, session tokens, CSRF tokens, ad scripts that change on every request. Your hash changes every single time even when the actual content is identical.
Fix: strip the noise before hashing.
from bs4 import BeautifulSoup
import re
def normalize_page(html):
soup = BeautifulSoup(html, 'html.parser')
# Remove scripts and styles
for tag in soup(['script', 'style', 'noscript']):
tag.decompose()
# Remove elements that change every load
for el in soup.select('[data-timestamp], [data-session], .ad-container'):
el.decompose()
text = soup.get_text(separator=' ', strip=True)
# Collapse whitespace
return re.sub(r'\s+', ' ', text).strip()
This gets you maybe 80% of the way. Some sites are worse than others.
JavaScript-rendered content. If the page relies on JS to load content (basically every SPA), requests.get gives you an empty shell. You need a real browser.
from playwright.sync_api import sync_playwright
def get_rendered_html(url):
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto(url, wait_until='networkidle')
html = page.content()
browser.close()
return html
Works but now you need Chromium installed, and each page fetch takes 3-10 seconds instead of 200ms.
Where I actually landed
For the 5 pages I needed to monitor, the full pipeline looks like:
- Playwright fetches rendered HTML
- BeautifulSoup strips dynamic elements
- Hash the normalized text
- Compare against stored state
- Send a Slack webhook if changed
def check_pages():
state = load_state()
changes = []
for url in URLS:
html = get_rendered_html(url)
normalized = normalize_page(html)
current_hash = hashlib.sha256(normalized.encode()).hexdigest()
prev_hash = state.get(url)
if prev_hash and prev_hash != current_hash:
changes.append(url)
state[url] = current_hash
save_state(state)
if changes:
notify_slack(changes)
Total code is under 100 lines. Runs in a GitHub Action every 6 hours. Free tier covers it easily.
Limitations (being honest)
- No visual diff — you know something changed but not what exactly
- BeautifulSoup normalization is brittle — new ad scripts or tracking pixels can cause false positives
- Playwright in GitHub Actions adds ~30s startup overhead
- No history — just current vs previous, cant see when changes happened over time
For my use case this was fine. If I needed visual diffs, change history, or monitoring more than ~20 pages, I'd probably reach for a dedicated tool instead of maintaining this myself.
Anyone running something similar? Curious what normalization strategies work for you.
Top comments (0)