我正在使用html5lib,在将其更新到最新版本后,我不断收到以下错误:
Traceback (most recent call last):
File "/home/travis/build/freelawproject/juriscraper/tests/test_everything.py", line 119, in test_scrape_all_example_files
site.parse()
File "/home/travis/build/freelawproject/juriscraper/juriscraper/AbstractSite.py", line 95, in parse
self.html = self._download()
File "/home/travis/build/freelawproject/juriscraper/juriscraper/AbstractSite.py", line 384, in _download
html_tree = self._make_html_tree(text)
File "/home/travis/build/freelawproject/juriscraper/juriscraper/opinions/united_states/federal_appellate/ca11_u.py", line 26, in _make_html_tree
e = html5parser.document_fromstring(text)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/lxml/html/html5parser.py", line 64, in document_fromstring
return parser.parse(html, useChardet=guess_charset).getroot()
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/html5lib/html5parser.py", line 235, in parse
self._parse(stream, False, None, *args, **kwargs)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/html5lib/html5parser.py", line 85, in _parse
self.tokenizer = _tokenizer.HTMLTokenizer(stream, parser=self, **kwargs)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/html5lib/_tokenizer.py", line 36, in __init__
self.stream = HTMLInputStream(stream, **kwargs)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/html5lib/_inputstream.py", line 149, in HTMLInputStream
return HTMLUnicodeInputStream(source, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'useChardet'
我使用的代码非常简单:
from lxml.html import html5parser
html5parser.document_fromstring(u'<html></html')
有什么想法吗?
事实证明,如果您将unicode对象馈送到document_fromstring
方法,它就会barfs。以前没有,因为只有当我更新依赖关系时才会发生这种情况。
无论如何,修复很容易:
html5parser.document_fromstring(u'<html></html'.encode('utf-8'))