Building a Price Tracker Bot
Architecture
Section titled “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
Section titled “Example: parse a price from HTML”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)
Section titled “Persist history (CSV)”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])Real sites often block scraping.
Prefer APIs, and respect site policies.
Visualize it
Section titled “Visualize it”A tracker bot loops through fetch, parse, and store steps, retrying politely when a request fails.
flowchart TD
A["Fetch the page"] --> B{"Request successful?"}
B -- "No" --> E["Wait/retry (respect rate limits)"]
E --> A
B -- "Yes" --> C["Parse the HTML"]
C --> D["Extract the price"]
D --> F["Store it"]
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading