A website monitor needs nearly all of the crawling topic in miniature. It checks robots.txt, fetches conditionally, so that an unchanged page costs a 304 response with no body, and fingerprints only the watched element, chosen by a CSS selector, so that timestamps and advertisements elsewhere on the page are ignored. A selector that matches nothing signals a layout change. If changes arrive as a Poisson process, a check every $I$ hours notices a change after $I/2$ on average, whatever the change rate. For an element that changes weekly, hourly checks (8,760 a year) wait 30 minutes and daily checks (365 a year) wait 12 hours. The tested Python monitor is tools/experiments/crawling/monitor.py.
A search engine's crawler tries to fetch as much of the web as it can. Most crawling programs written by individuals do the opposite. They watch a handful of pages, such as a price, a course listing, a status page or a government notice, and report when something changes. The only crawler I had written before this course was one of these, in PHP, years ago, with everything written by hand. How much of this topic does such a small program need, and how often should it look? It needs nearly all of the topic in miniature, and it should look as often as the delay it can tolerate requires, since a change waits on average half the interval between checks.
A website monitor here is a program that fetches a few specific pages on a schedule and reports when the part of each page that matters has changed. Nearly all of the topic's ideas carry over to it, scaled down: politeness, conditional requests and revisit rates, and fingerprints of the content that matters.
First we look for a source designed for programs. Then we design and test a monitor, and choose how often it should check. Worked problems on the schedule close the article.
Check for a better source first
Before writing code that reads pages designed for people, look for something designed for programs:
- Feeds. Many sites that publish updates, such as news, blogs, release notes, and announcements, offer an RSS or Atom feed, often linked in the page's HTML header. A feed lists recent changes directly.
- Interfaces. Many sites offer an API, a documented interface that returns data, often in JSON. Scripted pages usually load their data from such an interface even when it is not documented. The browser's developer tools show the requests.
- Sitemaps. A sitemap, often named in robots.txt, lists a site's pages, often with last-modified dates.
- Notifications. Some services will send email or call a web address supplied by the subscriber when something changes.
These are more stable than page layouts, cheaper for the site, and usually permitted explicitly. Also read the site's terms of service. Some forbid automated access, and robots.txt is not the only statement of a site's wishes.
Where none of these exists, the monitor must read the page itself.
The design
A monitor for one page needs only a few steps, run on a schedule:
- Check robots.txt (Koster, Illyes, Zeller, and Sassman, 2022), and stop if the page is disallowed.
- Fetch the page conditionally (Fielding, Nottingham, and Reschke, 2022, §13), sending the
ETagandLast-Modifiedvalues saved from the last fetch. If the server answers 304 (Not Modified), stop: nothing has changed and almost nothing was transferred. - Extract the part that matters, with a CSS selector, and normalize its whitespace.
- Fingerprint it with a hash, and compare with the saved fingerprint.
- Save the new state, including the validators and a copy of the text, and report any change.
Extracting a part of the page before fingerprinting is the key decision. Whole pages change constantly for reasons that do not matter: timestamps, advertisements, rotating recommendations, hidden security tokens in forms. A fingerprint of the whole page would report a change on nearly every visit. A fingerprint of the one element being watched reports only changes to it.
The next section gives the design as code.
A tested implementation
The following is the core of tools/experiments/crawling/monitor.py in the site repository, using the requests package and Beautiful Soup (beautifulsoup4; Richardson).
AGENT = "omnipedia-monitor/0.1 (+https://omnipedia.tech)"
def check(url, selector=None, state_file="monitor_state.json"):
path = Path(state_file)
state = json.loads(path.read_text()) if path.exists() else {}
old = state.get(url, {})
if not allowed(url): # robots.txt check
return "disallowed by robots.txt"
headers = {"User-Agent": AGENT}
if "etag" in old: headers["If-None-Match"] = old["etag"]
if "last_modified" in old: headers["If-Modified-Since"] = old["last_modified"]
r = requests.get(url, headers=headers, timeout=20)
if r.status_code == 304:
return "not modified (304)"
r.raise_for_status()
soup = BeautifulSoup(r.text, "html.parser")
part = soup.select_one(selector) if selector else soup.body or soup
if part is None:
return f"selector {selector!r} matched nothing; the page layout may have changed"
text = " ".join(part.get_text(" ").split())
digest = hashlib.sha256(text.encode()).hexdigest()
# ... save digest, text, and the new validators, then compare with old["digest"]
It was tested against a page served from a local test server, watching an element with the selector #price.
Example (a change elsewhere on the page). On one run, a timestamp elsewhere on the page has changed, so the server sends the full page with status 200. The monitor reports no change, because the fingerprint covers only the #price element, which did not change. That is run 3 below:
| Run | What happened to the page | Result |
|---|---|---|
| 1 | first visit | baseline saved |
| 2 | nothing | not modified (304), no body transferred |
| 3 | a timestamp elsewhere on the page changed | fetched (200), watched content unchanged |
| 4 | the price changed from 20 to 18 dollars | change reported, with old and new text |
| 5 | the page changed, and the watcher was given a selector that no longer exists | layout-change warning |
Run 3 shows why the selector matters: the page had changed, the server sent it in full, and the monitor correctly ignored the change. Run 5 covers the most common way monitors fail. When a site is redesigned, the selector stops matching. A monitor that treated "nothing found" as empty text would then either report a false change or, worse, silently watch nothing.
The monitor works. The remaining choice is how often it should run.
How often to check
The freshness model gives a monitor's schedule a simple arithmetic. Suppose the watched element changes on average once a week, at random times, as a Poisson process, and the monitor checks it every $I$ hours. Two quantities matter: how long a change goes unnoticed, and how many requests the monitor makes.
Example (a faster-changing element). Hourly checks notice a weekly change after 30 minutes on average. If the element changed twice a day instead, hourly checks would not notice each change sooner. The mean delay is still 30 minutes, since it depends only on the interval. Changes of a Poisson process fall uniformly in time: given the number of changes in an interval, their times are distributed as that many independent uniform times over it, sorted, a property proved in The Poisson Process. A change is therefore equally likely to happen at any point between two checks, and the time until the next check is uniform between 0 and $I$. The mean of a uniform variable on $(0, I)$ is $\frac{1}{I}\int_0^I x\,dx = I/2$, so the mean delay before a change is noticed is $I/2$. A simulation of hourly checks with changes twice a day gives a median mean delay of 29.9 minutes over 30 runs. The number of requests is just $8{,}760 / I$ checks a year. The fraction of them that find anything is the probability of at least one change in $I$ hours, $1 - e^{-\lambda I}$ with $\lambda = 1/168$ per hour.
| Check every | Checks a year | Checks that find a change | Mean delay before a change is noticed |
|---|---|---|---|
| 5 minutes | 105,120 | 0.05% | 2.5 minutes |
| 1 hour | 8,760 | 0.6% | 30 minutes |
| 6 hours | 1,460 | 3.5% | 3 hours |
| 1 day | 365 | 13.3% | 12 hours |
Going from daily to five-minute checks multiplies the requests by 288 to cut the delay from 12 hours to 2.5 minutes, and 99.95 percent of those checks find nothing. Whether that is worth it depends on what a delay costs, a concert ticket going on sale against a policy document being revised, but the table makes the price visible. Conditional requests lower the price of the empty checks, since a 304 response carries no body, though each still costs the server a request.
A simulation of one year of weekly changes, 30 runs, agreed with the $I/2$ delays. The median of the runs' mean delays was 29.4 minutes for hourly checks and 181 minutes for checks every six hours. The table is computed by tools/experiments/crawling/monitor_schedule.py.
Practical points
- Schedule rather than loop. Run the script from cron on Linux or macOS, or Task Scheduler on Windows, rather than leaving a program running with a sleep loop. A failed run then does not stop future ones.
- Choose the interval from the change rate. A page that changes weekly does not need checking every minute. The freshness analysis applies: frequent checks of a slowly changing page buy almost nothing. Hourly or daily is right for most purposes.
- Identify the monitor. Use a
User-Agentnaming the program, with a way to contact its operator, so the site's operator can see what is visiting. - Back off on errors. On status 429 or 503, or repeated failures, wait longer before the next attempt. Never retry in a tight loop.
- Know the robots.txt parser's limits. Before Python 3.13.14 and 3.14.5, both released in 2026 (Python Software Foundation, 2026),
urllib.robotparserapplied the first matching rule rather than the most specific one, as described in politeness and robots.txt. It also ignored wildcards in paths, so it could be either stricter or more permissive than the standard. Older versions remain in wide use, so checking the version, or reading the target's robots.txt by eye, is a sensible precaution. - Scripted pages. If the watched content does not appear in the HTML the server sends, the page builds it with JavaScript. Look for the underlying data request first. Rendering with a headless browser, through a library such as Playwright, works but is far heavier, for the monitor and the site alike. The deep web describes the trade-off.
- Keep history if it matters. A JSON file of last states is enough for a few pages. A small SQLite table of every observed version, with timestamps, shows when and how often something changed. The
difflibmodule in the Python standard library can show exactly what changed between versions.
Worked problems
The course text has no exercises on monitoring, so these problems are posed on the schedule model of this article, with the watched element changing as a Poisson process. The numbers are checked in monitor_schedule.py.
Problem 1 (an interval for a wanted delay). The watched element changes about once a week. How often must the monitor check for a change to be noticed within 10 minutes on average? What does that cost?
The mean delay is $I/2$, so $I/2 \le 10$ minutes needs $I \le 20$ minutes. A year has 8,760 hours, so checks every 20 minutes number $8{,}760 \times 3 = 26{,}280$ a year. A check finds a change with probability $1 - e^{-\lambda I}$ with $\lambda = 1/168$ per hour and $I = 1/3$ hour, which is $1 - e^{-1/504} = 0.00198$. About 0.2 percent of the checks, 52 of the 26,280, find anything, which is the 52 weekly changes of a year.
Problem 2 (a guarantee for most changes). With what interval are 95 percent of changes noticed within one hour?
The delay is uniform between 0 and $I$. If $I \le 1$ hour every change is noticed within the hour. If $I > 1$, the delay is at most 1 hour with probability $1/I$. Requiring $1/I \ge 0.95$ gives $I \le 1/0.95 = 1.053$ hours, about 63 minutes. An hourly check therefore does better than asked: it notices every change within the hour, with a mean delay of 30 minutes. The average and the guarantee are different questions. A mean delay of one hour would allow $I = 2$ hours, under which only half of the changes are noticed within the hour.
Problem 3 (changes the monitor cannot tell apart). An element changes twice a day on average and is checked every 6 hours. What fraction of checks find a change? How often does one check hide more than one change? What change rate would the monitor infer?
Here $\lambda = 1/12$ per hour and $I = 6$ hours, so $\lambda I = 0.5$ changes are expected between checks. The number of changes in an interval has a Poisson distribution with mean 0.5.
- A check finds a change unless there were none: $1 - e^{-0.5} = 0.393$.
- An interval holds two or more changes with probability $1 - e^{-0.5}(1 + 0.5) = 1 - 0.6065 \times 1.5 = 0.090$. In those intervals the monitor reports one change where there were several.
- Per interval, 0.5 changes happen and 0.393 reports are made, so there are $0.5/0.393 = 1.27$ changes for each report, and $1 - 0.393/0.5 = 21$ percent of the changes are never reported separately.
Counting reports gives a naive rate of $0.393$ per 6 hours, or $1.57$ changes a day, below the true 2. The correction of freshness and recrawling recovers the true rate from the same fraction: $-\ln(1 - 0.393)/6$ per hour is $0.0833$ per hour, exactly 2 a day. A monitor that keeps a history of its checks can therefore estimate how often its page really changes, and choose its interval from that.
What we have learned
A monitor is a crawler scaled down to a few pages. It checks robots.txt, fetches conditionally, and fingerprints only the watched element. A change waits on average half the interval between checks, whatever the change rate.
That ends the topic on web crawling. Every retrieval model so far has treated words as independent dimensions, so a query about cars misses a document about automobiles. Topic modeling, the next topic, represents documents by what they are about.
References
- Fielding, R., Nottingham, M., and Reschke, J. (2022). HTTP Semantics. RFC 9110, Internet Engineering Task Force. Sections 8.8 and 13 define validators and conditional requests. record · 2 pages
- Koster, M., Illyes, G., Zeller, H., and Sassman, L. (2022). Robots Exclusion Protocol. RFC 9309, Internet Engineering Task Force. record · 2 pages
- Python Software Foundation (2026). Changelog. Python documentation. docs.python.org/3/whatsnew/changelog.html (accessed November 2026). The entry for issue gh-138907 appears under Python 3.13.14 and 3.14.5 in the changelogs of those versions (docs.python.org/3.13/whatsnew/changelog.html and docs.python.org/3.14/whatsnew/changelog.html). record · 2 pages
- Richardson, L. Beautiful Soup documentation. Published on the web at crummy.com. record
Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 8 revisions