In this HackerRank HTML Parser - Part 2 in python problem solution, You are given an HTML code snippet of N lines. Your task is to print the single-line comments, multi-line comments, and the data.

HackerRank HTML Parser - Part 2 in python problem solution

HackerRank HTML Parser - Part 2 in python problem solution

from HTMLParser import HTMLParser

class MyHTMLParser(HTMLParser):
    def handle_comment(self,data):
        amount = 'Multi' if len(data.split('\n')) > 1 else 'Single'
        print '>>> ' + amount + '-line Comment'
        for dank in data.split('\n'):
            print dank
    def handle_data(self,data):
        if len(data) == 1:
            return
        print '>>> Data'
        for dank in data.split('\n'):
            print dank
html = ""       
for i in range(int(raw_input())):
    html += raw_input().rstrip()
    html += '\n'
    
parser = MyHTMLParser()
parser.feed(html)
parser.close()