• + 0 comments

    I was stuck during 10 minutes because I got "None" value in my output... Because this is the return value of the parse function if nothing...

    Nevermind, I finally fix this problem.

    Here the code :

    from html.parser import HTMLParser
    
    N = int(input())
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print("Start :", tag)
            if attrs:
                for element in attrs:
                    attribute_name = element[0]
                    attribute_value = element[1]
                    print(f"-> {attribute_name} > {attribute_value}")
    
        def handle_endtag(self, tag):
            print("End   :", tag)
    
        def handle_startendtag(self, tag, attrs):
            print("Empty :", tag)
            if attrs:
                for element in attrs:
                    attribute_name = element[0]
                    attribute_value = element[1]
                    print(f"-> {attribute_name} > {attribute_value}")
    
    
    parser = MyHTMLParser()
    
    for _ in range(N):
        current_line = input()
        if parser.feed(current_line):
            print(parser.feed(current_line))