diff --git a/html_comment_parser.py b/html_comment_parser.py new file mode 100644 index 00000000..592fa461 --- /dev/null +++ b/html_comment_parser.py @@ -0,0 +1,29 @@ +# HTML COMMENTS PARSER + +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 = '' +for i in range(n): + html_string += input().rstrip()+'\n' + +parser.feed(html_string) +parser.close() \ No newline at end of file diff --git a/html_tag_parser.py b/html_tag_parser.py new file mode 100644 index 00000000..b39b5b56 --- /dev/null +++ b/html_tag_parser.py @@ -0,0 +1,20 @@ +# For any given html-code this will output a nicely structured text with all tags and its attributes + +from html.parser import HTMLParser + +class MyHTMLParser(HTMLParser): + def handle_starttag(self, tag, attrs): + print ('Start :',tag) + for ele in attrs: + print ('->',ele[0],'>',ele[1]) + + def handle_endtag(self, tag): + print ('End :',tag) + + def handle_startendtag(self, tag, attrs): + print ('Empty :',tag) + for ele in attrs: + print ('->',ele[0],'>',ele[1]) + +MyParser = MyHTMLParser() +MyParser.feed(''.join([input().strip() for _ in range(int(input()))])) \ No newline at end of file