This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author hansokumake
Recipients docs@python, hansokumake
Date 2012-06-21.10:00:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1340272839.74.0.0138242037615.issue15120@psf.upfronthosting.co.za>
In-reply-to
Content
I tried this example from the documentation:

from html.parser import HTMLParser

class MyHTMLParser(HTMLParser):
    def handle_starttag(self, tag, attrs):
        print("Encountered a start tag:", tag)
    def handle_endtag(self, tag):
        print("Encountered an end tag :", tag)
    def handle_data(self, data):
        print("Encountered some data  :", data)

parser = MyHTMLParser(strict=False)
parser.feed('<html><head><title>Test</title></head>'
            '<body><h1>Parse me!</h1></body></html>')



According to documentation the output should be like this:
Encountered a start tag: html
Encountered a start tag: head
Encountered a start tag: title
Encountered some data  : Test
Encountered an end tag : title
Encountered an end tag : head
Encountered a start tag: body
Encountered a start tag: h1
Encountered some data  : Parse me!
Encountered an end tag : h1
Encountered an end tag : body
Encountered an end tag : html

but Python produced this:
Encountered some data  : <html>
Encountered some data  : <head>
Encountered some data  : <title>
Encountered some data  : Test
Encountered an end tag : title
Encountered an end tag : head
Encountered some data  : <body>
Encountered some data  : <h1>
Encountered some data  : Parse me!
Encountered an end tag : h1
Encountered an end tag : body
Encountered an end tag : html


If strict is set to True, it works correctly.
History
Date User Action Args
2012-06-21 10:00:39hansokumakesetrecipients: + hansokumake, docs@python
2012-06-21 10:00:39hansokumakesetmessageid: <1340272839.74.0.0138242037615.issue15120@psf.upfronthosting.co.za>
2012-06-21 10:00:39hansokumakelinkissue15120 messages
2012-06-21 10:00:38hansokumakecreate