Extract Titles from Sample HTML
Given a set of products, build a small HTML page from them (matching the notes' own product-card structure) and use BeautifulSoup's find_all() to extract and print every title.
Approach: construct an HTML string with one <div class="product"> per product, each containing a nested <h2 class="title">, then parse it and pull out the title text of every match.
Input: First line: the number of products n. Next n lines: title,price.
Output: One line per product: its title.
2 Wireless Headphones,$49.99 Bluetooth Speaker,$29.99
Wireless Headphones Bluetooth Speaker
- 1 <= n <= 100
Hint 1
BeautifulSoup(html, "html.parser") parses the constructed HTML into a navigable structure.
Hint 2
soup.find_all("h2", class_="title") returns every matching <h2 class="title"> element as a list.
Hint 3
.text on an element gives just its visible text, without the surrounding tags.
Building the HTML string first (one <div class="product"> per product, each with a nested <h2 class="title">) recreates the notes' own example structure from the given input. soup.findall("h2", class="title") then returns every matching title element as a list, and printing each one's .text gives just the visible title text.