Message163318
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. |
|
Date |
User |
Action |
Args |
2012-06-21 10:00:39 | hansokumake | set | recipients:
+ hansokumake, docs@python |
2012-06-21 10:00:39 | hansokumake | set | messageid: <1340272839.74.0.0138242037615.issue15120@psf.upfronthosting.co.za> |
2012-06-21 10:00:39 | hansokumake | link | issue15120 messages |
2012-06-21 10:00:38 | hansokumake | create | |
|