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
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.
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.
Fetch prices in parallel
Use AlterLab's batch endpoint to fetch multiple product URLs simultaneously, reducing total collection time.
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.
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 NoneReplace 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.
No credit card required · Up to 5,000 free scrapes · Balance never expire