CodeAgeBy Sitezack
Applied Python for ProsFiles, CSV and APIs0 XP
Chapter progress0/6

Lesson 7 of 7

Project: the price-watch bot

A classic monitoring bot: extract the products from a page, structure the data, spot the best deal and produce a CSV export.

The chapter's full chain: regex → dictionaries → aggregation → CSV string. The HTML is provided exactly as an HTTP request would have returned it.

pairs = re.findall(r"<h2>(.*?)</h2><span class='price'>(.*?)</span>", HTML)
for name, price in pairs:
    products.append({"name": name, "price": float(price)})

🎯 Exercise

From HTML: 1) build products, a list of dictionaries {"name": …, "price": …} (price as float) via re.findall with two groups; 2) store in cheapest the dictionary of the cheapest product; 3) build report, a CSV string starting with the line name,price followed by one name,price line per product. Print cheapest["name"].

PRO lesson

This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.

Discover PRO