here' another html parsing examplein we used simple method exported by this module to unquote html escape sequences ( entitiesin strings embedded in an html reply pageimport cgihtml parser cgi escape(" hello" ' &lt; &lt; &gt;hello&lt;/ &gt;html parser htmlparser(unescape( ' hellothis works for undoing html escapesbut that' all when we saw this solutioni implied that there was more general approachnow that you know about the method callback model of the html parser classthe more idiomatic way to handle entities during parse should make sense--simply catch entity callbacks in parser subclassand translate as neededclass parse(html parser htmlparser)def handle_data(selfdata)print(dataend=''def handle_entityref(selfname)map dict(lt=''print(map[name]end='' parse( feed( )print( hello better stillwe can use python' related html entities module to avoid hardcoding entity-to-character mappings for html entities this module defines many more entity names than the simple dictionary in the prior example and includes all those you'll likely encounter when parsing html text in the wilds ' &lt; &lt; &gt;hello&lt;/ &gt;from html entities import entitydefs class parse(html parser htmlparser)def handle_data(selfdata)print(dataend=''def handle_entityref(selfname)print(entitydefs[name]end='' parse( feed( )print( hello strictly speakingthe html entities module is able to map entity name to unicode code point and vice versaits table used here simply converts code point integers to characters with chr see this module' documentationas well as its source code in the python standard library for more details xml and html parsing