Message251792
For void elements such as (<link>, <img>), there doesn't need to have xhtml empty end tag. HtmlParser which relies on the XHTML empty end syntax failed to handle this situation.
from HTMLParser import HTMLParser
# create a subclass and override the handler methods
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.feed('<link rel="import"><img src="som">')
Encountered a start tag: link
Encountered a start tag: img
>>> parser.feed('<link rel="import"/><img src="som"/>')
Encountered a start tag: link
Encountered an end tag : link
Encountered a start tag: img
Encountered an end tag : img
Reference:
https://github.com/python/cpython/blob/bdfb14c688b873567d179881fc5bb67363a6074c/Lib/html/parser.py
http://www.w3.org/TR/html5/syntax.html#void-elements |
|
Date |
User |
Action |
Args |
2015-09-28 19:26:34 | Chenyun Yang | set | recipients:
+ Chenyun Yang |
2015-09-28 19:26:34 | Chenyun Yang | set | messageid: <1443468394.25.0.617953373069.issue25258@psf.upfronthosting.co.za> |
2015-09-28 19:26:34 | Chenyun Yang | link | issue25258 messages |
2015-09-28 19:26:34 | Chenyun Yang | create | |
|