JSONHTMLParser.py 555 B

123456789101112131415161718
  1. from HTMLParser import HTMLParser
  2. # HTMLParser which treats all tags as superfluous
  3. # markup, and appends every bit of data to an object
  4. # that gets returned later.
  5. class JSONHTMLParser(HTMLParser):
  6. # We are going to append out data to this.
  7. body = []
  8. # Every instance of data inside of an html node
  9. # will cause this function to be called.
  10. def handle_data (self, data):
  11. self.body.append(data)
  12. # After a parse of an html document, this method
  13. # will get the body parsed out as a string.
  14. def getBody(self):
  15. return str(self.body);