forked from arsho/Hackerrank_Python_Domain_Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTMLParserPart2.py
34 lines (27 loc) · 832 Bytes
/
HTMLParserPart2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Title : HTML Parser - Part 2
Subdomain : Regex and Parsing
Domain : Python
Author : Ahmedur Rahman Shovon
Created : 15 July 2016
Problem : https://www.hackerrank.com/challenges/html-parser-part-2/problem
"""
from html.parser import HTMLParser
class CustomHTMLParser(HTMLParser):
def handle_comment(self, data):
number_of_line = len(data.split("\n"))
if number_of_line > 1:
print(">>> Multi-line Comment")
else:
print(">>> Single-line Comment")
if data.strip():
print(data)
def handle_data(self, data):
if data.strip():
print(">>> Data")
print(data)
parser = CustomHTMLParser()
n = int(input())
html_string = "".join(input().rstrip() + "\n" for _ in range(n))
parser.feed(html_string)
parser.close()