本文共 294 字,大约阅读时间需要 1 分钟。
数据解析——bs4解析
1. 模块安装
pip install bs4
from bs4 import BeautifulSoup
2. bs4 解析流程
初始化 BeautifulSoup 对象
page = BeautifulSoup(html,"html.parser")
- page.find(“标签名”,“属性”=“值”) 查找某个元素,只会找到一个结果 当属性为class时,为避免与类定义冲突,属性名使用==class_==表示
- page.find_all(“标签名”,“属性”=“值”) 找到一堆结果
- .text 获取标签中的文本息
- .get(“属性名”) 获取属性值
3.
转载地址:http://nbpowy.baihongyu.com/