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.
fromhtml.parserimportHTMLParserclassMyHTMLParser(HTMLParser):defhandle_starttag(self,tag,attrs):"""HandlethestarttagofanHTMLelement.Parameters:tag(str):Thenameofthetag.attrs(list):Alistof(name,value)pairscontainingtheattributes.Returns:None"""print(tag)forattrinattrs:print(f"-> {attr[0]} > {attr[1]}")if__name__=='__main__':# Read the number of lines in the HTML code snippetn=int(input())# Read the HTML code snippet and join the lines into a single stringhtml_code=''.join([input()for_inrange(n)])# Create an instance of the HTML parser and feed it the HTML codeparser=MyHTMLParser()parser.feed(html_code)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Detect HTML Tags, Attributes and Attribute Values
You are viewing a single comment's thread. Return to all comments →