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.
Created on 2012年06月21日 10:00 by hansokumake, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg163318 - (view) | Author: hansokumake (hansokumake) | Date: 2012年06月21日 10:00 | |
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.
|
|||
| msg163331 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2012年06月21日 13:41 | |
What exact version of python have you used? The example works here with 3.2.3+. |
|||
| msg163345 - (view) | Author: hansokumake (hansokumake) | Date: 2012年06月21日 16:27 | |
I'm sorry. It's my fault. I still use Python 3.2.2. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:31 | admin | set | github: 59325 |
| 2012年06月21日 16:35:13 | ezio.melotti | set | resolution: not a bug stage: resolved |
| 2012年06月21日 16:27:53 | hansokumake | set | status: open -> closed messages: + msg163345 |
| 2012年06月21日 13:41:21 | ezio.melotti | set | assignee: docs@python -> ezio.melotti messages: + msg163331 |
| 2012年06月21日 10:33:20 | fdrake | set | nosy:
+ fdrake |
| 2012年06月21日 10:24:00 | r.david.murray | set | nosy:
+ ezio.melotti |
| 2012年06月21日 10:00:39 | hansokumake | create | |