Command Palette

Search for a command to run...

Hectal
Phase 4: Ingestion: From Files to Searchable Chunks
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

  1. Navigation and footer blocks are removed with their contents
  2. Tags become spaces and whitespace is collapsed
  3. Entities are decoded
  4. Entities are decoded after tags are removed
  5. 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.