关于python3.6 我导入bs4的时候没用

About python3.6 when I import bs4, it doesn't work

我将 bs4 导入为:

from bs4 import BeautifulSoup

但它会抛出这样的错误:

Traceback (most recent call last):
  File "/Users/koudai232/Desktop/test.py", line 4, in <module>
    from bs4 import BeautifulSoup
  File "/usr/local/lib/python3.6/site-packages/bs4/__init__.py", line 30, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "/usr/local/lib/python3.6/site-packages/bs4/builder/__init__.py", line 308, in <module>
    from . import _htmlparser
  File "/usr/local/lib/python3.6/site-packages/bs4/builder/_htmlparser.py", line 7, in <module>
    from html.parser import (
ImportError: cannot import name 'HTMLParseError'
[Finished in 0.1s with exit code 1]
[cmd: ['/usr/local/bin/python3', '-u', '/Users/koudai232/Desktop/test.py']]
[dir: /Users/koudai232/Desktop]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

但它适用于 python2.7。 我将 bs4 更新为:

pip install --upgrade beautifulsoup4

还不行。

如何解决这个问题,谢谢~!

您应该升级您的 beautifulsoup 模块以适应 python 3.6。 从 4.4.0 开始,BeautifulSoup 与 Python 3.5 兼容。及以上

pip3 install --upgrade beautifulsoup4