class parsepage(htmlparser)def handle_starttag(selftagattrs)print('tag start:'tagattrsdef handle_endtag(selftag)print('tag end'tagdef handle_data(selfdata)print('data 'data rstrip()nowcreate web page' html text stringwe hardcode one herebut it might also be loaded from fileor fetched from website with urllib requestpage ""spamclick this ""finallykick off the parse by feeding text to parser instance--tags in the html text trigger class method callbackswith tag names and attribute sequences passed in as argumentsparser parsepage(parser feed(pagedata tag starthtml [data tag starth [data spamtag endh data tag startp [data click this tag starta [('href''data python tag enda data link tag endp data tag endhtml as you can seethe parser' methods receive callbacks for events during the parse much like sax xml parsingyour parser class will need to keep track of its state in attributes as it goes if it wishes to do something more specific than print tag namesattributesand content watching for specific tagscontentthoughmight be as simple as checking names and setting state flags moreoverbuilding object trees to reflect the page' structure during the parse would be straightforward text and language