Input Format
The first line contains an integer , the number of lines in the HTML code snippet.
The next  lines contain HTML code.
Constraints
Output Format
Print the HTML tags, attributes and attribute values in order of their occurrence from top to bottom in the snippet.
Format your answers as explained in the problem statement.

hackerrank detect html tags attributes and attribute values problem solution in python

Problem solution in Python 3 programming language.

from HTMLParser import HTMLParser

class MyHTMLParser(HTMLParser):
    def handle_starttag(self, tag, attrs):
        print(tag)
        for attr in attrs:
            print("->"," > ".join(attr))

parser = MyHTMLParser()

html = ""
for i in range(int(input())):
    html += input()
    html += '\n'

parser.feed(html)

Second solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
    def handle_starttag(self, tag, attrs):
        print(tag)
        [print('-> {} > {}'.format(*attr)) for attr in attrs]
html = '\n'.join([input() for _ in range(int(input()))])
parser = MyHTMLParser()
parser.feed(html)
parser.close()

Problem solution in Python 2 programming language.

from HTMLParser import HTMLParser

class MyHTMLParser(HTMLParser):
    def handle_starttag(self, tag, attrs):
        print tag
        for attr in attrs:
            print "->"," > ".join(attr)

parser = MyHTMLParser()

html = ""
for i in range(int(raw_input())):
    html += raw_input()
    html += '\n'

parser.feed(html)