Building a Price Tracker Bot
Architecture
- Fetch product page (or API)
- Parse price
- Save price history (CSV/SQLite)
- Compare with threshold
- 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 coffeeWas this page helpful?
Let us know how we did
