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

Lesson 6 of 7

Extract data from HTML

Scraping means extracting structured data from an HTML page. For simple patterns, re.findall is enough.

re.findall(r"<h2>(.*?)</h2>", html) returns the list of contents captured by the parentheses — the non-greedy .*? stops at the first closing tag.

import re
names = re.findall(r"<h2>(.*?)</h2>", html)

🎯 Exercise

Extract from HTML the list names of the three product names (contents of the h2 tags) with re.findall, then print names.

PRO lesson

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

Discover PRO