我已经使用安装了 beautifulsouppip install beautifulsoup4
但是当我输入时from bs4 import BeautifulSoup
显示此错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/bs4/__init__.py", line 30, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "/usr/lib/python2.7/dist-packages/bs4/builder/__init__.py", line 314, in <module>
from . import _html5lib
File "/usr/lib/python2.7/dist-packages/bs4/builder/_html5lib.py", line 70, in <module>
class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):
AttributeError: 'module' object has no attribute '_base'
我应该怎么办?
答案1
我不确定这是否有帮助,但是 beautifulsoup 需要的 python2.7 版本与 python3.6 版本不同。bs4 适用于 python 3.6,而 bs3 适用于 python2.7。