导入beautifulsoup时出错

时间:2017-05-02 10:16:27

标签: python beautifulsoup pip

导入bs4时出现奇怪的错误。 我在其他地方找不到任何帮助。 我尝试安装html和future。

完成追溯:

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)

2 个答案:

答案 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
    

    获取任何标签数据只需替换&#34; a&#34;带有你想要的标签

  3. 交叉检查文件名是否已命名&#34; bs4.py&#34;或者类似于&#34; HTMLParser.py&#34;

答案 1 :(得分:0)

  

The reinstall failed..

由于pip install --upgrade --force-reinstall beautifulsoup4失败了。我猜你的系统中安装了多个版本的python,或者模块安装不正确。

您应该先尝试pip uninstall <module>卸载该模块,然后重新安装pip install <module>