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.
HTML Parser - Part 1
HTML Parser - Part 1
Sort by
recency
|
161 Discussions
|
Please Login in order to post a comment
A nice one:
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): print("Start :", tag) for attr in attrs: print("->", attr[0], ">", attr[1] if attr[1] else "None")
Read input
n = int(input().strip()) html_code = '\n'.join(input() for _ in range(n))
Create parser and feed the HTML code
parser = MyHTMLParser() parser.feed(html_code)