Skip to content

Building a Price Tracker Bot

Architecture

  1. Fetch product page (or API)
  2. Parse price
  3. Save price history (CSV/SQLite)
  4. Compare with threshold
  5. Notify (email/telegram)

Example: parse a price from HTML

price_parse_template.py
from bs4 import BeautifulSoup
 
html = "<span class='price'>$199.99</span>"
soup = BeautifulSoup(html, "html.parser")
price_text = soup.select_one(".price").get_text(strip=True)
print(price_text)
price_parse_template.py
from bs4 import BeautifulSoup
 
html = "<span class='price'>$199.99</span>"
soup = BeautifulSoup(html, "html.parser")
price_text = soup.select_one(".price").get_text(strip=True)
print(price_text)

Persist history (CSV)

save_history.py
import csv
from datetime import datetime
 
 
def append_price(csv_path: str, price: str):
    with open(csv_path, "a", newline="", encoding="utf-8") as f:
        w = csv.writer(f)
        w.writerow([datetime.now().isoformat(), price])
save_history.py
import csv
from datetime import datetime
 
 
def append_price(csv_path: str, price: str):
    with open(csv_path, "a", newline="", encoding="utf-8") as f:
        w = csv.writer(f)
        w.writerow([datetime.now().isoformat(), price])

Notes

Real sites often block scraping.

Prefer APIs, and respect site policies.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did