data<\/em> argument is the text content of HTML.<\/p>\n\n\n\nfrom HTMLParser import HTMLParser\n\nclass MyHTMLParser(HTMLParser):\n def handle_data(self, data):\n print \"Data :\", data<\/code><\/pre>\n\n\n\n<\/span>Task<\/strong><\/span><\/h2>\n\n\n\nYou are given an HTML<\/em> code snippet of N<\/strong><\/em> lines.
Your task is to print the single-line comments, multi-line comments<\/em> and the data<\/em>.<\/p>\n\n\n\nPrint the result in the following format:<\/p>\n\n\n\n
>>> Single-line Comment \nComment\n>>> Data \nMy Data\n>>> Multi-line Comment \nComment_multiline[0]\nComment_multiline[1]\n>>> Data\nMy Data\n>>> Single-line Comment: <\/code><\/pre>\n\n\n\nNote<\/strong>: Do not print data<\/em> if data == '\\n'<\/code>.<\/p>\n\n\n\n<\/span>Input Format<\/strong><\/span><\/h2>\n\n\n\nThe first line contains integer N<\/strong><\/em>, the number of lines in the HTML<\/em> code snippet.
The next N<\/em><\/strong> lines contains HTML<\/em> code.<\/p>\n\n\n\n<\/span>Constraints<\/strong><\/span><\/h2>\n\n\n\n- 0 < N<\/em> < 100<\/strong><\/li><\/ul>\n\n\n\n
<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nPrint the single-line comments, multi-line comments<\/em> and the data<\/em> in order of their occurrence from top to bottom in the snippet.<\/p>\n\n\n\nFormat the answers as explained in the problem statement.<\/p>\n\n\n\n
Sample Input<\/strong><\/p>\n\n\n\n4\n<!--[if IE 9]>IE9-specific content\n<![endif]-->\n<div> Welcome to HackerRank<\/div>\n<!--[if IE 9]>IE9-specific content<![endif]--><\/code><\/pre>\n\n\n\nSample Output<\/strong><\/p>\n\n\n\n>>> Multi-line Comment\n[if IE 9]>IE9-specific content\n<![endif]\n>>> Data\n Welcome to HackerRank\n>>> Single-line Comment\n[if IE 9]>IE9-specific content<![endif]<\/code><\/pre>\n\n\n\n<\/span>Solution – HTML Parser – Part 2 in Python<\/strong><\/span><\/h2>\n\n\n\nfrom html.parser import HTMLParser\n\nclass MyHTMLParser(HTMLParser):\n def handle_comment(self, comment):\n if '\\n' in comment:\n print('>>> Multi-line Comment')\n else:\n print('>>> Single-line Comment')\n\n print(comment)\n\n def handle_data(self, data):\n if data == '\\n': return\n print('>>> Data')\n print(data) \nhtml = \"\" \nfor i in range(int(input())):\n html += input().rstrip()\n html += '\\n'\n \nparser = MyHTMLParser()\nparser.feed(html)\nparser.close()<\/pre>\n\n\n\n