HackerRank Python - Detect HTML Tags, Attributes and Attribute Values




You are given an HTML code snippet of N lines.
Your task is to detect and print all the HTML tags, attributes and attribute values.

Print the detected items in the following format:



  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. from html.parser import HTMLParser
  3. class MyHTMLParser(HTMLParser):
  4. def handle_starttag(self, tag, attrs):
  5. print(tag)
  6. [print('-> {} > {}'.format(*attr)) for attr in attrs]
  7. html = '\n'.join([input() for _ in range(int(input()))])
  8. parser = MyHTMLParser()
  9. parser.feed(html)
  10. parser.close()




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube