2016-08-22 12 views
3

html5libをインストールしようとしています。最初は最新のバージョン(8,9ネイション)をインストールしようとしましたが、BeautifulSoupと競合してしまったので、古いバージョン(0.9999999、seven nines)を試すことにしました。私はそれをインストールし、私はそれを使用しようとすると:html5lib:TypeError:__init __()予期しないキーワード引数 'encoding'があります

>>> with urlopen("http://example.com/") as f: 
    document = html5lib.parse(f, encoding=f.info().get_content_charset()) 

私はエラーを取得:

Traceback (most recent call last): 
    File "<pyshell#11>", line 2, in <module> 
    document = html5lib.parse(f, encoding=f.info().get_content_charset()) 
    File "C:\Python\Python35-32\lib\site-packages\html5lib\html5parser.py", line 35, in parse 
    return p.parse(doc, **kwargs) 
    File "C:\Python\Python35-32\lib\site-packages\html5lib\html5parser.py", line 235, in parse 
    self._parse(stream, False, None, *args, **kwargs) 
    File "C:\Python\Python35-32\lib\site-packages\html5lib\html5parser.py", line 85, in _parse 
    self.tokenizer = _tokenizer.HTMLTokenizer(stream, parser=self, **kwargs) 
    File "C:\Python\Python35-32\lib\site-packages\html5lib\_tokenizer.py", line 36, in __init__ 
    self.stream = HTMLInputStream(stream, **kwargs) 
    File "C:\Python\Python35-32\lib\site-packages\html5lib\_inputstream.py", line 151, in HTMLInputStream 
    return HTMLBinaryInputStream(source, **kwargs) 
TypeError: __init__() got an unexpected keyword argument 'encoding' 

間違って何をして、私は何をすべき?私は何かがBS4に関してhtml5libの最新バージョンで壊れていた、html5lib.treebuilders._baseが、もはや参照

答えて

6

は、BS4をUSNGは、互換性のある最新バージョンは7つのナインとの1であるように思わ4.4.1それが正常に動作し、次のようにあなたがそれをインストールした後:名前が変更されたRename treebuilders._base to .base to reflect public statusをコミットあなたがこのの変化を見ることができます

In [1]: import bs4 

In [2]: bs4.__version__ 
Out[2]: '4.4.1' 

In [3]: import html5lib 

In [4]: html5lib.__version__ 
Out[4]: '0.9999999' 

In [5]: from urllib.request import urlopen 

In [6]: with urlopen("http://example.com/") as f: 
    ...:   document = html5lib.parse(f, encoding=f.info().get_content_charset()) 
    ...:  

In [7]: 

pip3 install -U html5lib=="0.9999999" 

はBS4 4.4.1を使用してテスト

)(

class HTMLBinaryInputStream(HTMLUnicodeInputStream): 
    """Provides a unicode stream of characters to the HTMLTokenizer. 

    This class takes care of character encoding and removing or replacing 
    incorrect byte-sequences and also provides column and line tracking. 

    """ 

    def __init__(self, source, override_encoding=None, transport_encoding=None, 
       same_origin_parent_encoding=None, likely_encoding=None, 
       default_encoding="windows-1252", useChardet=True): 

設定override_encoding = f.info:

それでもhtml5lib/_inputstream.pyHTMLBinaryInputStreamで、最新バージョンを使用しているので、あなたが見誤差があるにはエンコードの引数を持っていません.get_content_charset()はこのトリックを行う必要があります。

In [16]: bs4.__version__ 
Out[16]: '4.5.1' 

In [17]: html5lib.__version__ 
Out[17]: '0.999999999' 

In [18]: with urlopen("http://example.com/") as f: 
      document = html5lib.parse(f, override_encoding=f.info().get_content_charset()) 
    ....:  

In [19]: 
:また、BS4の最新バージョンにアップグレード

はhtml5libの最新バージョンで正常に動作します

関連する問題