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.
class MyHTMLParser(HTMLParser):
def handle_comment(self, data: str) -> None:
if not len(data.splitlines()) == 1:
print('>>> Multi-line Comment')
for line in data.splitlines():
print(line)
else:
print('>>> Single-line Comment')
print(data)
def handle_data(self, data: str) -> None:
if not data == '\n':
print('>>> Data')
for line in data.splitlines():
print(line)
html = ""
for i in range(int(input())):
html += input().rstrip()
html += '\n'
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: str) -> None: if not len(data.splitlines()) == 1: print('>>> Multi-line Comment') for line in data.splitlines(): print(line) else: print('>>> Single-line Comment') print(data)
html = "" for i in range(int(input())): html += input().rstrip() html += '\n'
parser = MyHTMLParser() parser.feed(html) parser.close()