安装
在命令提示符框中直接输入pip install beautifulsoup4
介绍
beautifulsoup是python的一个第三方库,和xpath一样,都是用来解析html数据的。
引入
from bs4 import BeautifulSoup
使用
将一段文档传入BeautifulSoup的构造方法,就能得到一个文档的对象。
bs = BeautifulSoup(open('index.html',encoding='utf-8'),'lxml')
print(bs)
注意:这样上传文档的话,BeautifulSoup里面需要两个参数。一个为open方法,一个是固定写法,