← Questions

Parse HTML into an element tree and query it

0
AppleCodingLast asked Aug 2026

You are asked to "write an HTML parser" with no definition of the input, the output or the edge cases. Part of the exercise is pinning that down: ask for examples, then write down what the input looks like, what you return, and which cases you handle (nesting, self-closing tags, attributes, text, malformed markup). Then parse the markup into a tree of elements and answer queries over it with a depth-first search, such as finding every element with a given tag or attribute.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding