3

I am working on a python script where I use data from a HTML file. I use the HTMLParser module, with my own handle_endtag and so on, as described here

When handling exceptions, I am looking at handling the HTMLParser.HTMLParseError exception. Yet I cannot make a test case where the parser throws an exception! Two questions:

Is the parser so good at parsing anything that handling the exception is useless?

Can someone cook up a test input that makes the parser throw the exception ? (I want to see what it looks like!)

Poor, tortured, parser.

1 Answer 1

2

HTMLParser.HTMLParseError is raised on broken markup and in some cases when it encounters an error while parsing.

from HTMLParser import HTMLParser

parser = HTMLParser()

parser.feed('<![..]>')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.