2017-05-02 73 views
1

導入bs4時出現奇怪的錯誤。 我在其他地方找不到任何幫助。 我試過安裝html和未來。導入beautifulsoup時出錯

完整回溯:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "C:\Python27\lib\site-packages\bs4\__init__.py", line 35, in <module> 
    from .builder import builder_registry, ParserRejectedMarkup 
    File "C:\Python27\lib\site-packages\bs4\builder\__init__.py", line 7, in <module> 
    from bs4.element import (
    File "C:\Python27\lib\site-packages\bs4\element.py", line 10, in <module> 
    from bs4.dammit import EntitySubstitution 
    File "C:\Python27\lib\site-packages\bs4\dammit.py", line 53, in <module> 
    class EntitySubstitution(object): 
    File "C:\Python27\lib\site-packages\bs4\dammit.py", line 74, in EntitySubstitution 
    CHARACTER_TO_HTML_ENTITY_RE) = _populate_class_variables() 
    File "C:\Python27\lib\site-packages\bs4\dammit.py", line 62, in _populate_clas 
s_variables 
    character = chr(codepoint) 
ValueError: chr() arg not in range(256) 
+0

哪一行,在哪個文件? – marmeladze

+0

我剛剛調用命令提示符並輸入import bs4 –

+0

有什麼幫助?我完全失去了...已經嘗試了一切... –

回答

0
  1. 試試這個

    from bs4 import BeautifulSoup  
    

    工程與python3和BS 4藏漢

  2. 或者,也許這會有所幫助:

    from bs4 import BeautifulSoup as bs 
    import urllib 
    url="http://example.com" 
    soup = bs(urllib.urlopen(url)) 
    for link in soup.findAll('a'): 
    print link.string 
    

    爲了獲取標記的任何數據只需更換「一」與標籤你想

  3. 交叉檢查,如果文件名被命名爲「bs4.py」或可能像「HTMLParser.py」

+0

沒有完全相同的回溯 –

0

The reinstall failed..

由於pip install --upgrade --force-reinstall beautifulsoup4失敗你。我猜你的系統中安裝了多個python版本,或者模塊安裝不正確。

你應該嘗試通過pip uninstall <module>先卸載模塊,然後進行全新安裝pip install <module>