I'm using Python and html5lib to check if a bit of HTML code entered on a form field is valid.
I tried the following code to test a valid fragment but I'm getting an unexpected error (at least for me):
>>> import html5lib
>>> from html5lib.filters import lint
>>> fragment = html5lib.parseFragment('<p><script>alert("Boo!")</script></p>')
>>> walker = html5lib.getTreeWalker('etree')
>>> [i for i in lint.Filter(walker(fragment))]
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/xyz/html5lib-1.0b3-py2.7.egg/html5lib/filters/lint.py", line 28, in __iter__
raise LintError(_("Tag name is not a string: %(tag)r") % {"tag": name})
LintError: Tag name is not a string: u'p'
What I'm doing wrong?
My default encoding is utf-8
:
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'