Have HTMLParser differentiate between link-text and other data?
问题 Say I have html code similar to this: <a href="http://example.org/">Stuff I do want</a> <p>Stuff I don't want</p> Using HTMLParser's handle_data doesn't differentiate between the link-text(stuff I do want)(Is this even the right term?) and the stuff I don't want. Does HTMLParser have a built-in way to have handle_data return only link-text and nothing else? 回答1: Basically you have to write a handle_starttag() method as well. Just save off every tag you see as self.lasttag or something. Then,