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()
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

donate a cup of tea :)

Join Our Facebook Group

Share this solution


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