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.
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
def handle_comment(self, data):
if '\n' in data:
print(">>> Multi-line Comment")
for line in data.split('\n'):
print(line)
else:
print(">>> Single-line Comment")
print(data)
def handle_data(self, data):
if data.strip():
print(">>> Data")
print(data)
n = int(input())
html_content = "\n".join(input() for _ in range(n))
parser = MyHTMLParser()
parser.feed(html_content)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
HTML Parser - Part 2
You are viewing a single comment's thread. Return to all comments →
from html.parser import HTMLParser class MyHTMLParser(HTMLParser): def handle_comment(self, data): if '\n' in data: print(">>> Multi-line Comment") for line in data.split('\n'): print(line) else: print(">>> Single-line Comment") print(data)
n = int(input()) html_content = "\n".join(input() for _ in range(n)) parser = MyHTMLParser() parser.feed(html_content)