Detect HTML Tags, Attributes and Attribute Values

  • + 0 comments
    from html.parser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, att):
            print(tag)
            self.print_atributes(att)
        def print_atributes(self, att):
            for name, val in att:
                print(f'-> {name} > {val}')
            
    
    parser = MyHTMLParser()
    for _ in range(int(input())):
        parser.feed(input())