我将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
它还没有用。
如何解决这个问题,谢谢〜!
答案 0 :(得分:2)
你应该使用python 3.6升级你的beautifulsoup模块。
从4.4.0开始,BeautifulSoup
与Python 3.5兼容。以上
pip3 install --upgrade beautifulsoup4