Advanced5 steps

How to Build a Price Comparison Tool

Comparing prices across multiple retailers requires fetching product pages from different sites simultaneously, normalizing diverse price formats, and matching the same product across different naming conventions — all on a recurring schedule.

Step-by-Step Guide

1

Define your product catalog

Create a list of products with their URLs on each retailer you want to monitor. Use a consistent product identifier (SKU, GTIN) to match products across sites.

2

Build site-specific extractors

Write a selector configuration for each retailer's price element. Store these as a dictionary keyed by domain so you can apply the right extractor per URL.

3

Fetch prices in parallel

Use AlterLab's batch endpoint to fetch multiple product URLs simultaneously, reducing total collection time.

4

Normalize and compare

Convert all prices to a common currency and decimal format. Sort by price to find the cheapest option and flag significant price changes.

5

Schedule and alert

Run comparisons on a schedule. Send alerts when a tracked product drops below a price threshold.

Code Example

import requests
from bs4 import BeautifulSoup

RETAILER_SELECTORS = {
    "example-store-a.com": ".product-price",
    "example-store-b.com": "#price-display",
}

def get_price(url: str, api_key: str) -> str | None:
    from urllib.parse import urlparse
    domain = urlparse(url).netloc.replace("www.", "")
    selector = RETAILER_SELECTORS.get(domain)
    if not selector:
        return None

    response = requests.post(
        "https://alterlab.io/api/v1/scrape",
        headers={"X-API-Key": api_key, "Content-Type": "application/json"},
        json={"url": url, "render_js": True},
    )
    html = response.json().get("html", "")
    el = BeautifulSoup(html, "html.parser").select_one(selector)
    return el.get_text(strip=True) if el else None

Replace YOUR_API_KEY with your key from the dashboard. No credit card required.

Ready to try it?

Run this tutorial on live websites with AlterLab's API. Start free — no credit card required.

Frequently Asked Questions

Responsible Use

AlterLab is designed for extracting publicly available data. Always review the terms of service for any website you access, respect robots.txt directives, and ensure your use case complies with applicable laws in your jurisdiction.

More tutorials

Browse all how-to guides for web scraping — from beginner extractions to advanced multi-page pipelines.

Your first scrape.
Sixty seconds.

$1 free balance. No credit card. No SDK.Just a POST request.

terminal
curl -X POST https://api.alterlab.io/v1/scrape \
-H "X-API-Key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "formats": ["markdown"]}'

No credit card required · Up to 5,000 free scrapes · Balance never expire

    How to Build a Price Comparison Tool with Web Scraping | AlterLab | AlterLab