📅  最后修改于: 2022-03-11 14:45:15.356000             🧑  作者: Mango
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)