📜  如何使用python代码示例对html文件进行处理

📅  最后修改于: 2022-03-11 14:45:15.356000             🧑  作者: Mango

代码示例1
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)