gpt4 book ai didi

python - 如何在 html5lib 中修复 "unexpected keyword argument ' useChardet'"

转载 作者:太空狗 更新时间:2023-10-30 01:06:17 24 4
gpt4 key购买 nike

我正在使用 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'))

关于python - 如何在 html5lib 中修复 "unexpected keyword argument ' useChardet'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38577080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com