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

完整的追溯:

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)

最佳答案

试试这个

  from bs4 import BeautifulSoup


同样适用于python3和BS 4
也许这会有所帮助:

 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


要获取标签的任何数据,只需将“ a”替换为所需的标签
交叉检查文件名是否命名为“ bs4.py”或类似“ HTMLParser.py”的名称

关于python - 导入beautifulsoup时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43735393/

10-13 09:40