from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
def handle_comment(self,data):
print("Encountered comment:- ",data)
pos = self.getpos()
print("At line ",pos[0],"and position",pos[1])
parser = MyHTMLParser()
html_file = open("simple.html")
if html_file.mode == "r":
contents = html_file.read()
parser.feed(contents)