[New-bugs-announce] [issue15120] Different behavior of html.parser.HTMLParser
hansokumake
report at bugs.python.org
Thu Jun 21 12:00:39 CEST 2012
New submission from hansokumake <hansokumake at seznam.cz>:
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.
----------
assignee: docs at python
components: Documentation
messages: 163318
nosy: docs at python, hansokumake
priority: normal
severity: normal
status: open
title: Different behavior of html.parser.HTMLParser
type: behavior
versions: Python 3.2
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15120>
_______________________________________
More information about the New-bugs-announce
mailing list