How to Build a Competitor Price Tracker With Playwright
Senior Web Scraping Engineer
TL;DR:
- A competitor price tracker needs a stable offer key. Match the retailer, variant, market, seller, and purchase type before comparing prices.
- Playwright can wait for the rendered price. Scope the locator to the product summary so the tracker does not read a recommendation or reference price.
- Keep the amount and currency together. Store the displayed string and a decimal representation so reviewers can audit the parser.
- A failed capture should leave the last good price intact. Send access, navigation, and parse problems to collection monitoring.
Introduction
A product page can show a sale price, a reference price, and a row of related products in the same viewport. If a tracker reads the first currency symbol, its alert can point to an offer the customer never selected.
The Playwright example below reads the price inside one product summary on a public demo storefront. The practical part comes after extraction: deciding when two prices describe the same offer.
Install Playwright
This example uses the Playwright Python package and an installed copy of Google Chrome. Install the package in a project environment and confirm Chrome is available on the worker. Use an explicit allowlist of product URLs for the scheduler and start with a single worker.
bash
python3 -m pip install playwright
Configure the Offer You Will Track
A tracker should define its comparison key before it visits a page. Include the retailer, product or variant, market, seller, and purchase type. Keep currency and unit basis in the comparison checks. The Schema.org Offer model distinguishes an offer from the underlying item and includes separate price and currency properties.
If the offer depends on market routing, use the same approved network context for comparable captures. The price monitoring infrastructure workflow covers routing choices. In this demo, the browser reads a single UK-style display and verifies the GBP format directly.
Start Scraping with Scrapeless
Power up your web scraping and automation workflow with Scrapeless!
Sign up today and get $5 in free credit — no credit card required.Claim your free credit now in the Scrapeless Dashboard.
Read One Offer From a Public Demo Page
A Playwright capture can check navigation, wait for a unique price locator, and emit a compact observation. The Playwright locator reference explains how locators target elements and how strict operations behave when multiple elements match. The example scopes both title and price to the same product summary.
python
import json
import re
from datetime import datetime, timezone
from decimal import Decimal
from playwright.sync_api import sync_playwright
URL = "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"
with sync_playwright() as playwright:
browser = playwright.chromium.launch(channel="chrome")
try:
page = browser.new_page(locale="en-GB")
response = page.goto(URL, wait_until="domcontentloaded", timeout=20_000)
if response is None or not response.ok or page.url != URL:
raise RuntimeError("Expected the demo product page")
summary = page.locator(".product_main")
price = summary.locator(".price_color")
price.wait_for(state="visible", timeout=10_000)
display_price = price.inner_text().strip()
match = re.fullmatch(r"£([0-9]+\.[0-9]{2})", display_price)
if match is None:
raise ValueError("Unexpected demo price format")
print(json.dumps({
"product_key": "books-to-scrape:a-light-in-the-attic",
"title": summary.get_by_role("heading", level=1).inner_text(),
"final_url": page.url,
"offer_type": "listed",
"price": str(Decimal(match.group(1))),
"currency": "GBP",
"display_price": display_price,
"observed_at": datetime.now(timezone.utc).isoformat(),
}, ensure_ascii=False))
finally:
browser.close()
The script prints a record with a string for the decimal amount, the displayed value, and the time. The Internet timestamp standard defines a way to represent the UTC offset so observations can be aligned across workers.
Compare Successful Captures
A price change should compare the current observation with the previous comparable observation for the same offer. Persist both before sending an alert. If the job finds the same value again, leave the price history unchanged or store a confirmation according to your reporting needs.
| Capture result | Tracker action |
|---|---|
| Same offer and lower price | Record a price decrease and link both observations |
| Same offer and same price | Record collection health or a confirmation |
| Currency or purchase type changed | Recheck the offer key before comparing |
| Access challenge, missing price, or unexpected redirect | Record a collection issue and keep the last valid observation |
When switching from the demo to a real target, use a verified locale parser and store the price basis. A membership offer and a regular offer deserve separate series. For pages that render after selection, wait for the selected variant marker and price region together. Keep parser versions so a false alert after a page redesign can be traced.
When to Move Playwright to a Managed Browser
Start with a local worker. Move to a managed browser for web automation when worker upkeep or repeated runs become a practical constraint. The browser overview describes cloud sessions, and Scrapeless pricing helps estimate that change. Keep the Playwright locator and offer key under your control. The Puppeteer proxy workflow covers the related routing concern.
Conclusion
The demo prints one product offer. Before using the same approach across retailers, test what happens when the price region is empty, the currency changes, or the page redirects. None of those observations should replace the last comparable price.
Ready to Build Your Competitor Price Tracker?
Join the community on Discord or Telegram to talk with developers building price tracking workflows. Create an account in the Scrapeless Dashboard to get started.
FAQ
Q: How often should a competitor price tracker run?
Choose a cadence that matches how the team uses the alert and the site's permitted request budget. A price report and a time-sensitive promotion monitor can use different schedules.
Q: Do you need a proxy for Playwright price monitoring?
A permitted regional route can reproduce a local storefront view. A single-market demo or an approved local source can use its ordinary connection.
Q: What should the tracker do if a site shows an access challenge?
Record the failure and review the access path with the site owner. Keep the previous successful offer as the comparison baseline.
Q: Can this run without an AI agent?
Playwright and a scheduler can collect and compare observations. Run with bounded concurrency and validate changed locators on a known product page.
Q: Can you monitor any competitor storefront?
Use approved surfaces and review applicable terms, collection limits, and reuse rights with counsel when the scope is unclear.
At Scrapeless, we only access publicly available data while strictly complying with applicable laws, regulations, and website privacy policies. The content in this blog is for demonstration purposes only and does not involve any illegal or infringing activities. We make no guarantees and disclaim all liability for the use of information from this blog or third-party links. Before engaging in any scraping activities, consult your legal advisor and review the target website's terms of service or obtain the necessary permissions.


