I have this small class:
class HTMLTagStripper(HTMLParser):
def __init__(self):
self.reset()
self.fed = []
def handle_data(self, data):
self.fed.append(data)
def handle_starttag(self, tag, attrs):
if tag == 'a':
return attrs[0][1]
def get_data(self):
return ''.join(self.fed)
parsing this HTML code:
<div id="footer">
<p>long text.</p>
<p>click <a href="somelink.com">here</a>
</div>
This is the result I get: long text click here
but I want to get: long text click somelink.com
Is there a way to do this?