I want to extract text from a html file, specifically from the <p> and <h1> Tag.
I did see the code from the python doc regarding this topic:
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print("Encountered a start tag:", tag)
def handle_endtag(self, tag):
print("Encountered an end tag :", tag)
def handle_data(self, data):
print("Encountered some data :", data)
parser = MyHTMLParser()
parser.feed('<html><head><title>Test</title></head>'
'<body><h1>Parse me!</h1></body></html>')
But I'm not sure how to go from here, in order to extract only texts within certain tags (
and . Any hint and advice in the right direction is welcomed! (I do not want to use beautiful soup or any external libraries)