1.定义:HTML或XML解析器,依赖于lxml
2.安装:
Anaconda Prompt:conda install beautifulsoup4
3.使用流程
1> 导入模块
from bs4 import BeautifulSoup
2> 创建解析对象
soup = BeautifulSoup(html,'lxml')
3> 对象调用方法查找节点
rList = soup.find_all(条件)
4.BeautifulSoup支持的解析库
1> lxml:速度快,文档容错能力强
2> html.parser:Python标准库,速度一般,容错一般
3> xml:速度快,文档容错能力强
5.常用方法
1> find_all():返回的是列表
rList = soup.find_all('div',{'id':'test'})
2> 节点对象.get_text()
3> 节点对象.string