BeautifulSoup入门
来源:互联网 发布:linux dhcp服务配置 编辑:程序博客网 时间:2024/06/02 04:43
BeautifulSoup库入门
BeautifulSoup库的理解
BeautifulSoup库是解析、遍历、维护”标签树”的功能库
示例代码:
from bs4 import BeautifulSoupsoup = BeautifulSoup("<html>data</html>","html.parser")#第一参数是html文档,第二个参数指定parser类型是html.parsersoup2 = BeautifulSoup(open("d://demo.html"),"html.parser")
BeautifulSoup解析器
BeautifulSoup类的基本元素
使用BeautifulSoup遍历HTML DOM树
实例代码:
from bs4 import BeautifulSoupimport requestsresponse = requests.get("http://www.icourse163.org/learn/BIT-1001870001")html = response.textsoup = BeautifulSoup(html,"html.parser")tag = soup.aprint(tag.contents)#打印子节点列表for child in tag.children:#迭代所有子节点 print(child)for descendant in tag.descendants:#迭代所有子孙节点 print(descendantprint(tag.parent)#打印父亲节点for parent in tag.parents:#迭代所有父节点 print(parent)print(tag.next_sibling)#下一个兄弟节点
阅读全文
0 0
- BeautifulSoup入门
- BeautifulSoup入门代码
- python 中BeautifulSoup入门
- python 中BeautifulSoup入门
- python 中BeautifulSoup入门
- BeautifulSoup库入门
- BeautifulSoup 入门指南
- python爬虫之BeautifulSoup入门
- 使用BeautifulSoup解析html入门
- BeautifulSoup库入门级方法
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- beautifulsoup
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- 从ORACLE到SQL SERVER的透明网关的安装和配置
- html实时效果查看的实现
- OC中条件编译须留意是否导入了相关头文件
- laravel导出Excel
- Android Studio中配置Retrolambda插件【mac】
- BeautifulSoup入门
- Java线程死锁查看分析方法
- 嵌入式学习文章
- Android 触摸事件传递流程解析
- 2.5 数组
- 服务器容错保护(Hystrix依赖隔离)
- 哈希表C开源的uthash的简单初步封装(二)
- 个人开发者如何通过人工智能盈利?智能原理及阿尔法狗详解
- MM 委外加工(Subconctracting)流程