HackerRank Python - HTML Parser - Part 1

Hypertext Markup Language is a standard markup language used for creating World Wide Web pages.

Parsing is the process of syntactic analysis of a string of symbols. It involves resolving a string into its component parts and describing their syntactic roles.

An HTMLParser instance is fed HTML data and calls handler methods when start tags, end tags, text, comments, and other markup elements are encountered.

  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 ('Start :', tag)
  6. for ele in attrs:
  7. print ('->', ele[0], '>', ele[1])
  8. def handle_endtag(self, tag):
  9. print ('End :', tag)
  10. def handle_startendtag(self, tag, attrs):
  11. print ('Empty :', tag)
  12. for ele in attrs:
  13. print ('->', ele[0], '>', ele[1])
  14. parser = MyHTMLParser()
  15. for _ in range(int(input())):
  16. parser.feed(input())

download android app