Intermediate5 steps

How to Scrape E-commerce Prices

Price monitoring requires fetching the same product URLs repeatedly and extracting current prices reliably. E-commerce sites frequently update their page structure, and prices are often loaded dynamically — making standard HTTP scrapers unreliable.

Step-by-Step Guide

1

Build your product URL list

Compile the list of product URLs you want to monitor. Include the product ID in your storage so you can match prices across time.

2

Fetch each page with browser rendering

Send each URL to the AlterLab API with render_js enabled to ensure dynamically loaded prices are captured.

3

Extract the price with a CSS selector

Inspect the target product page to find the CSS selector for the price element. Use BeautifulSoup or lxml to extract it from the rendered HTML.

4

Store prices with timestamps

Write price records to a database or CSV file with timestamps. Compare new records to previous ones to detect price changes.

5

Schedule recurring jobs

Run your price-extraction script on a schedule (hourly, daily) using cron, Celery, or a cloud scheduler.

Code Example

import requests
from bs4 import BeautifulSoup

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

price = get_price(
    "https://www.example-store.com/product/123",
    "YOUR_API_KEY",
    ".product-price",
)
print(f"Current price: {price}")

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 Scrape E-commerce Prices for Price Monitoring | AlterLab | AlterLab