Detect HTML Tags, Attributes and Attribute Values - Hacker Rank Solution
class HTMLParser.HTMLParser
An HTMLParser instance is fed HTML data and calls handler methods when start tags, end tags, text, comments, and other markup elements are encountered.
To learn more, refer to https://docs.python.org/2/library/htmlparser.html.
To learn more, refer to https://docs.python.org/2/library/htmlparser.html.
from HTMLParser import HTMLParser class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): print tag for attr in attrs: print "->"," > ".join(attr) parser = MyHTMLParser() html = "" for i in range(int(raw_input())): html += raw_input() html += '\n' parser.feed(html)
No comments:
Post a Comment