We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Python
  3. Regex and Parsing
  4. HTML Parser - Part 1
  5. Discussions

HTML Parser - Part 1

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 141 Discussions, By:

recency

Please Login in order to post a comment

  • lucasopoka
    3 weeks ago+ 0 comments
    from html.parser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print("Start :", tag)
            [print(f'-> {i[0]} > {i[1]}') for i in attrs]
        def handle_endtag(self, tag):
            print ("End   :", tag)
        def handle_startendtag(self, tag, attrs):
            print ("Empty :", tag)
            [print(f'-> {i[0]} > {i[1]}') for i in attrs]
            
    parser = MyHTMLParser()
    for _ in range(int(input())):
        parser.feed(input())
    
    0|
    Permalink
  • andrew323
    3 weeks ago+ 0 comments
    from html.parser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            if not self.inComment:
                print(f'Start : {tag}')
                for attr in attrs:
                    print(f'-> {attr[0]} > {attr[1]}')
        
        def handle_startendtag(self, tag, attrs):
            if not self.inComment:
                print(f'Empty : {tag}')
                for attr in attrs:
                    print(f'-> {attr[0]} > {attr[1]}')
           
        def handle_endtag(self, tag):
            if not self.inComment:
                print(f'End   : {tag}')
    
    parser = MyHTMLParser()
    for _ in range(int(input())):
        parser.feed(input())
    
    0|
    Permalink
  • jarithfry
    3 weeks ago+ 0 comments
    from html.parser import HTMLParser
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print(f"Start : {tag}" + "".join([f"\n-> {attr[0]} > {attr[1]}" for attr in attrs if attrs]))
            
        def handle_endtag(self, tag):
            print(f"End   : {tag}")
            
        def handle_startendtag(self, tag, attrs):
            print(f"Empty : {tag}" + "".join([f"\n-> {attr[0]} > {attr[1]}" for attr in attrs if attrs]))
            
            
    if __name__ == '__main__':
        html = ""
        parser = MyHTMLParser()
        for _ in range(int(input())):
            html += input()
        parser.feed(html)
    
    0|
    Permalink
  • jovanjoviemmanu1
    1 month ago+ 0 comments

    from html.parser import HTMLParser

    class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): print ('Start :', tag) for ele in attrs: print ('->', ele[0], '>', ele[1])

    def handle_endtag(self, tag):
        print ('End   :', tag)
    
    def handle_startendtag(self, tag, attrs):
        print ('Empty :', tag)
        for ele in attrs:
            print ('->', ele[0], '>', ele[1])
    

    parser = MyHTMLParser() for _ in range(int(input())): parser.feed(input())

    0|
    Permalink
  • ryan_a_gard
    2 months ago+ 0 comments
    from html.parser import HTMLParser
    
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print("Start :", tag)
    
            for attr in attrs:
                print(f"-> {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(f"-> {attr[0]} > {attr[1]}")
    
    N = int(input())
    parser = MyHTMLParser()
    
    parser.feed("\n".join([input() for _ in range(N)]))
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy