# Python Playwright price watcher

A browser based price watcher reads a visible price, saves a full page screenshot, and alerts when the value changes or crosses your target. Tokay runs Chromium inside a Scheduled Service and keeps the history files between deployments.

The default check uses Tokay's public pricing page, so you can prove the browser and selector before choosing a product. After that, Config changes the URL and CSS selector without a code edit.

## Facts

- Runtime: Python
- Framework: Playwright
- Service types: Scheduled Service
- Resources: SQLite, Persistent files
- Required secrets: None

## What it does

Each run opens the configured page in Chromium and reads the first element matching `WATCH_SELECTOR`.

The script saves the parsed value to SQLite and replaces `last-price.png` with a current screenshot. Its run result names the browser version, observed price, previous price, and total history count.

A changed price creates an alert. Add `TARGET_PRICE` when you also want to know that a price moved down through a specific number.

## Deploy it

Bring this folder to Tokay any way you like. Paste or upload it in the dashboard, push it with git, or hand it to your AI agent along with [our agent instructions](https://app.tokay.io/llms.txt). Tokay figures out the rest.

Working in Claude, ChatGPT, VS Code, or another MCP client? Connect the [Tokay MCP server](https://tokay.io/docs/platform-mcp) and ask your agent to deploy this example. It signs in through your browser, so there is no token to paste.

New to Tokay? The [getting started guide](https://tokay.io/getting-started) walks you through your first deploy.

## Try it

1. Choose **Run Now**, then download `last-price.png` from **Saved Files**.
2. Note the history count in the run result and deploy the same code again.
3. Run it once more. The screenshot is refreshed and the count grows in the preserved database.

## Watch another price

Open the Service's **Environment** page and find `WATCH_URL` under **From your code**. Choose **Set shared value** and enter the public product page. Set `WATCH_SELECTOR` the same way with a CSS selector for the visible price. Add `TARGET_PRICE` if you want an alert when the price crosses that number.

Set `ALERT_WEBHOOK_URL` to a Slack or Discord incoming webhook if you want alerts sent outside Tokay. A price change always alerts. Crossing the target adds a second reason to the same message.

Before watching a new site, check its terms and robots guidance. Keep the schedule gentle and do not automate a page that asks automated clients to stay away.

## How it works

You can use a real product page because Tokay provides Chromium in the Service environment. Playwright loads the page, finds the selected text, parses its first currency shaped number, and captures the screenshot.

If nothing matches, the run fails with a message that names both selector and URL. Successful runs write under Tokay's persistent data directory. Read [Files and persistent storage](https://tokay.io/docs/persistent-storage) to see how those files survive.

## Secrets

| Name | Required | Purpose |
| --- | --- | --- |
| `ALERT_WEBHOOK_URL` | No | Sends alerts to a Slack or Discord incoming webhook. |

## Grow from here

Try the [PDF invoice generator](/examples/python-pdf-invoice-generator) when system libraries should render a document from a web form instead.

## Source files

- [requirements.txt](https://tokay.io/examples/src/python-playwright-price-watcher/requirements.txt)
- [watcher.py](https://tokay.io/examples/src/python-playwright-price-watcher/watcher.py)

## Download and source

- [Download the complete project](https://tokay.io/examples/downloads/python-playwright-price-watcher.zip)
- Last updated: 2026-07-31
- Example revision: `52c7b7f`
- [View this revision on GitHub](https://github.com/tokayio/tokay-examples/tree/52c7b7ffd52e157375b08f1f11ff4fbe6c498642/python-playwright-price-watcher)
- [Host a web scraper that runs on a schedule](https://tokay.io/use-cases/host-web-scraper)
