BeautifulSoup常用方法
来源:互联网 发布:数据库的概念模型设计 编辑:程序博客网 时间:2024/06/07 18:14
1. 初始化
res=urllib.urlopen('www.baidu.com').read()
p=bs4.BeautifulSoup(res)
2. 查找指定标签
eg:要找到符合<div class="select_user">的所有标签
p.findAll('div',{'class':'select_user'})
反复利用标签特征可以找到最终需要的标签
3. 直接加标签名可以找到所有子标签
eg:找到所有<td>标签
p.td()
4. 直接以字典形式,可以访问标签内对应属性的值
eg:要找到<a href='www.csdn.net'>中href的值'www.csdn.net'
p.['href']
4、要获得标签的内容,可以直接加.string
eg:要找到<p>1235</p>中的'1235'
p.string
参考
http://panyongzheng.iteye.com/blog/1948944
0 0
- BeautifulSoup常用方法
- BeautifulSoup常用的函数
- BeautifulSoup 对象方法
- BeautifulSoup库入门级方法
- BeautifulSoup库中find_all()方法
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- beautifulsoup
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- beautifulsoup
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- Android 对话框Dialog的使用,最基本,最基础的使用
- iOS学习笔记—— 应用程序设置
- Android开发工具大集合(一)
- Word search
- oc基础知识
- BeautifulSoup常用方法
- Android Netd详细分析(一)概述
- 星路关于gridview的卡顿现象
- 业务流程管理,你准备好了吗?
- 黑马程序员_Java基础——网络编程(第7篇)
- 003
- VC++常用数据类型
- linux下shell任务控制命令与快捷键jobs/fg/bg/ctrl+z/kill
- Longest Substring Without Repeating Characters