Following up on our Web Scraping 101, let’s build something useful: a Python Price Tracker script that checks a product price and tells us if it’s on sale.
Note: Amazon aggressively blocks standard scrapers. We need to send “Headers” to pretend to be a real browser.
Step 1: Setup with Headers
import requests
from bs4 import BeautifulSoup
# The product you want to track
URL = "https://www.amazon.com/dp/B08N5WRWNW" (Example PS5 Controller)
# Pretend to be a regular browser
HEADERS = ({'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
'Accept-Language': 'en-US, en;q=0.5'})
page = requests.get(URL, headers=HEADERS)
soup = BeautifulSoup(page.content, "html.parser")Step 2: Find the Price
You need to inspect the Amazon page to find the exact ID of the price tag. Usually, it’s #priceblock_ourprice or .a-price-whole.
try:
# Try finding the whole number part of the price
price_whole = soup.find("span", class_="a-price-whole").text
# Remove commas if price is over $1000 (e.g., 1,200 -> 1200)
price_final = float(price_whole.replace(',', '').replace('.', ''))
print(f"Current Price: ${price_final}")
TARGET_PRICE = 60.00
if price_final < TARGET_PRICE:
print("ALERT! Price dropped! Buy it now!")
# HERE you could add your SEND EMAIL code!
else:
print("Price is still too high.")
except AttributeError:
print("Could not find the price. Amazon might have changed the page structure.")Important Warning
Web scraping can be fragile. If Amazon changes their website code, your script might break and need updating. This is normal!





