RAG and Vector Search · Exercise 1 of 6Next
Intermediate
Turn an HTML page into clean text
Write html_to_text(raw) that returns the visible text of an HTML string.
Remove whole script, style, nav and footer blocks (with everything inside them), then remove the remaining tags, then decode (to a space), <, > and &, and finally collapse all runs of whitespace into single spaces and trim the ends.
The order matters: decode entities last, so that <b> shown as text is not mistaken for a tag.
What Check tests
- Navigation and footer blocks are removed with their contents
- Tags become spaces and whitespace is collapsed
- Entities are decoded
- Entities are decoded after tags are removed
- Scripts and styles are removed with their contents
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.