Sort by

recency

|

168 Discussions

|

  • + 0 comments
    from html.parser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print("Start :", tag)
            for attr in attrs:
                print("->", attr[0], ">", attr[1])
    
        def handle_endtag(self, tag):
            print("End   :", tag)
            
        def handle_startendtag(self, tag, attrs):
            print("Empty :", tag)
            for attr in attrs:
                print("->", attr[0], ">", attr[1])
    
    parser = MyHTMLParser()
    
    for i in range(int(input())):
        parser.feed(input())
    
  • + 0 comments
    from html.parser import HTMLParser
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print("Start".ljust(5), ":", tag)
            for n, v in attrs:
                print(f"-> {n} > {v}")
        def handle_endtag(self, tag):
            print("End".ljust(5), ":", tag)
        def handle_startendtag(self, tag, attrs):
            print("Empty".ljust(5), ":", tag)
            for n, v in attrs:
                print(f"-> {n} > {v}")
    t = ''.join(input() for _ in range(int(input())))
    parser = MyHTMLParser()
    parser.feed(t)
    
  • + 0 comments
    from html.parser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print ("Start :", tag)
            if attrs:
                for attr, value in attrs:
                    print(f"-> {attr} > {value}")
            
        def handle_endtag(self, tag):
            print ("End   :", tag)
        def handle_startendtag(self, tag, attrs):
            print(f"Empty : {tag}")
            if attrs:
                for attr, value in attrs:
                    print(f"-> {attr} > {value}")
            
    
    parser = MyHTMLParser()
    
    for i in range(int(input())):
        parser.feed(input())
    
  • + 1 comment

    ValueError: invalid literal for int() with base 10: "HTML Parser - I

    HackerRank


    " I am getting this error no matter what, do you have any recommendations to resolve this error,

  • + 1 comment

    Are we supposed to know HTML for solving this problem?? I'm unable to understand how to parse the HTML data exactly.