Prompt
How do I set up a web scraping tool for tracking pricing changes across merchants?
Latest observation
To set up a web scraping tool for tracking pricing changes across merchants, it helps to build it as a small pipeline:
- Define the target data
- Collect product pages
- Extract product names/prices
- Store snapshots over time
- Compare changes and alert
Here’s a practical approach.
1) Check legal and technical constraints first
Before scraping any merchant site:
- Review the site’s Terms of Service
- Check robots.txt
- Avoid scraping pages that require bypassing logins, CAPTCHAs, or anti-bot protections
- Use polite request rates and identify your crawler with a user agent
- Prefer official APIs or affiliate/product feeds when available
If you’re monitoring merchants at scale, this matters a lot for reliability and compliance.
2) Decide what you need to track
For each merchant/product, define:
- Product name
- Price
- Currency
- Availability
- SKU / product ID
- URL
- Timestamp of capture
Example data model:
{
"merchant": "Example Store",
"product_name": "Wireless Mouse",
"price": 19.99,
"currency": "USD",
"availability": "in_stock",
"url": "https://example.com/product/123",
"captured_at": "2026-10-19T12:00:00Z"
}
3) Choose a scraping stack
A common stack:
- Python
- Requests + BeautifulSoup for simple static pages
- Playwright or Selenium for JavaScript-rendered pages
- SQLite/PostgreSQL for storage
- Cron / GitHub Actions / Airflow for scheduling
- Email/Slack/webhook alerts for notifications
If you’re just starting, Python + Requests + BeautifulSoup is easiest.
4) Build the scraper
For static pages
Install dependencies:
pip install requests beautifulsoup4 lxml
Example scraper:
import requests
from bs4 import BeautifulSoup
def scrape_product(url):
headers = {
"User-Agent": "PriceMonitorBot/1.0 (+contact@example.com)"
}
r = requests.get(url, headers=headers, timeout=20)
r.raise_for_status()
soup = BeautifulSoup(r.text, "lxml")
name = soup.select_one(".product-title").get_text(strip=True)
price_text = soup.select_one(".price").get_text(strip=True)
# Example parsing, adapt to site format
price = float(price_text.replace("$", "").replace(",", ""))
return {
"url": url,
"product_name": name,
"price": price
}
For dynamic pages
If price loads via JavaScript, use Playwright:
pip install playwright
playwright install
Example:
from playwright.sync_api import sync_playwright
def scrape_dynamic_product(url):
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.goto(url, wait_until="networkidle")
name = page.locator(".product-title").inner_text()
price_text = page.locator(".price").inner_text()
price = float(price_text.replace("$", "").replace(",", ""))
browser.close()
return {
"url": url,
"product_name": name,
"price": price
}
5) Store data in a database
Use a database to save each scrape as a time-stamped record.
Example SQLite schema:
CREATE TABLE price_snapshots (
id INTEGER PRIMARY KEY AUTOINCREMENT,
merchant TEXT NOT NULL,
product_name TEXT NOT NULL,
price REAL NOT NULL,
currency TEXT NOT NULL,
url TEXT NOT NULL,
captured_at TEXT NOT NULL
);
Then insert each scrape result as a new snapshot.
Why snapshots? Because price changes are detected by comparing current vs previous records.
6) Detect price changes
Compare the latest snapshot with the previous one for the same product.
Example logic:
- Fetch most recent two records for a product
- If price differs, log the change
- Trigger an alert
Pseudo-code:
if old_price != new_price:
print(f"Price changed from {old_price} to {new_price}")
You may also want to track:
- Percentage change
- Stock status changes
- Price drops only
- Threshold-based alerts
7) Schedule scraping
Run the scraper regularly:
- Cron: simplest for a server/VPS
- GitHub Actions: good for lightweight periodic jobs
- Airflow: for larger workflows
- Celery/Redis: if you need distributed tasks
Example cron entry to run every 6 hours:
0 */6 * * * /usr/bin/python3 /path/to/scraper.py
8) Add alerting
When a price changes, notify yourself or a team.
Common channels:
- Slack webhook
- Discord webhook
- SMS via Twilio
Example Slack webhook request:
import requests
def send_slack_alert(message, webhook_url):
requests.post(webhook_url, json={"text": message})
9) Handle common scraping issues
Merchant sites often change or block scrapers. Plan for:
- HTML structure changes
- Rate limiting / 429 responses
- Bot detection
- Missing/hidden prices
- Multi-currency formatting
- Regional pricing differences
Best practices:
- Add retries with backoff
- Use caching
- Rotate user agents carefully and ethically
- Keep selectors configurable per merchant
- Log failures and monitor scraper health
10) Make it maintainable
If you’ll monitor many merchants, don’t hardcode each site. Use a config file like:
merchants:
- name: "Store A"
url: "https://storea.com/product/1"
selectors:
name: ".product-title"
price: ".price"
- name: "Store B"
url: "https://storeb.com/item/9"
selectors:
name: "h1.title"
price: ".cost"
This lets you add merchants without rewriting code.
Recommended architecture
A simple robust setup:
- Scraper service: fetch product pages
- Parser layer: extract fields per merchant
- DB: store snapshots
- Change detector: compare latest to prior data
- Notifier: send alerts
- Scheduler: run periodically
If you want a quick MVP
Start with:
- Python
- Requests + BeautifulSoup
- SQLite
- Cron
- Email/Slack alerts
That’s enough for a small price-tracking tool.
If you want, I can also provide:
- a complete Python starter project,
- a database schema + scraper example, or
- a version using Playwright for JavaScript-heavy sites.