Beautiful Soup下载链接:http://www.crummy.com/software/BeautifulSoup/download/4.x/
有多个版本可供选择
1、解压后通过 setup.py 来安装
打开 cmd, 输入: cd + setup.py 文件路径
我的文件路径是:
C:\Users\27511\Desktop\beautifulsoup4-4.1.0\beautifulsoup4-4.1.0
>>> 所以我输入
cd C:\Users\27511\Desktop\beautifulsoup4-4.1.0\beautifulsoup4-4.1.0
再输入 Python setup.py install , 命令行即可
Python setup.py install
大概 5s 左右就安装成功
如果无法运行, 就手动将 \beautifulsoup4-4.1.0\build\lib 下的 bs4 文件移动到 python 安装路径下的 Lib 文件夹里。
如果运行时报错:
ImportError: cannot import name 'HTMLParseError' from 'html.parser'
就打开安装路径下的 \bs4\builder 下的 _ init _.py 文件打开
把文件末尾的这些代码删除就可以了
from . import _htmlparser
register_treebuilders_from(_htmlparser)
try:
from . import _html5lib
register_treebuilders_from(_html5lib)
except ImportError:
# They don't have html5lib installed.
pass
Beautiful Soup使用文档: https://beautifulsoup.readthedocs.io/zh_CN/v4.4.0/#id8