Skip to main content
You track prices or stock on public product pages and want to know when they change. This walkthrough reads one value from each page, stores it in SQLite and prints what changed since the last run. Check each site’s terms and robots.txt before you monitor it. The script skips pages that robots.txt disallows and waits at least the file’s Crawl-delay between page loads.

What Apostate changes

Each site gets its own user data directory, where Chromium keeps cookies and storage. The first launch on a directory stores a seed in its apostate/identity file, and every later launch presents the same machine with the same cookies. The site sees the same Windows desktop on each run, with its consent choice and region settings kept. Seeds and identity covers the identity file.

Set up

apostate fonts install windows is for Linux and macOS hosts (Fonts). The folder holds two files:
  • monitor.py reads the pages, stores each value in prices.db and prints the changes. It keeps one user data directory per site in profiles/.
  • demo_shop.py is a local shop on 127.0.0.1:8765 whose prices change from one run to the next. monitor.py uses it when you pass no pages.

The script

watch_site() launches a browser on one site’s user data directory, reads the site’s robots.txt, and loads each page with a delay in between:
The script fetches robots.txt in the same browser and parses it with Python’s urllib.robotparser:

Run it

The first run stores a value for each page:
The second run compares with the first:
The seed is the same on both runs because it comes from the identity file in the site’s user data directory. The demo shop’s robots.txt disallows /cart and sets Crawl-delay: 2, so the pages load 2 to 3 seconds apart. Every value is a row in the observations table of prices.db:

Watch your own pages

Pass each page with the CSS selector of the value to read. Repeat --watch for more pages:
The script groups pages by host name, and each host gets its own user data directory. Run the script from cron or another scheduler at the interval you need.

Points for this job

  • One user data directory per site. A site’s cookies, such as a consent choice or a selected region and currency, stay in its directory from run to run. Copy the profiles/ directory to back it up. The copy presents the same machine.
  • Seeds. The identity file holds each directory’s seed. To choose the seed yourself, write it to profiles/<host>/apostate/identity before the first launch. Seeds and identity covers the file.
  • Pacing. --delay sets the seconds between page loads on one site, 30 by default, plus up to half as much again at random. A larger Crawl-delay in robots.txt wins. The script reads sites one after another, one page at a time.
  • Region. Prices often depend on the visitor’s country. --locale and --timezone fix the locale and timezone. With APOSTATE_PROXY set, every page loads through that proxy. Use an exit in the same region on every run, and pass that region’s locale and timezone, because the script turns off the GeoIP lookup. Proxies covers proxy URLs.
  • Values. The script stores the element’s text as it is. A selector that matches nothing within 10 seconds stores (not found), so a page whose markup changed shows up as a change. Parse numbers yourself if you need them.
  • Headless. Reading pages needs no window. The default headless launch presents the persona’s screen.