HackerRank Python - HTML Parser - Part 1




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

Parsing
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.

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.



  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())




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