Detect HTML Tags, Attributes and Attribute Values

  • + 0 comments
    from html.parser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print (tag)
            if attrs:
                for attr, value in attrs:
                    print(f"-> {attr} > {value}")
    
    
    html = ""       
    for i in range(int(input())):
        html += input().rstrip()
        html += '\n'
        
    parser = MyHTMLParser()
    parser.feed(html)
    parser.close()