python的BeautifulSoup用法
来源:互联网 发布:淘宝开店培训班多少钱 编辑:程序博客网 时间:2024/06/08 14:38
python的BeautifulSoup用法
首先导入模块
from bs4 import BeautifulSoup
soup=BeautifulSoup(opener)
1.tag标签法
soup.head.title
如果是一层层的标签包下去只取每层标签第一个
2.contents法
比如三元素:[u'\n','<html>xxxx</html>',u'\n']
soup.contents 返回列表,不是单一元素
soup.contents[x].contents 是对各列表的取值
3..next法
只对单一元素进行.next,比如
soup.contents[1]=u'HTML'
soup.contents[2]=u'\n'
则soup.content[1].next等价于soup.contents[2]
搜索法
.find('p') 返回字符串
.findall('p') 返回列表
4. .attrs[x]取属性值法
在上述各方法获取标签体之后,通过对标签实施attrs得到一个内部属性列表
在标签后新增.attrs['id']取得该标签内部id的属性值
soup.contents[3].attrs[1]='/'
阅读全文
0 0
- python的BeautifulSoup用法
- python BeautifulSoup的简单用法
- python爬虫--BeautifulSoup的简单用法
- python爬虫之BeautifulSoup的用法
- python beautifulsoup简单用法
- Python爬虫BeautifulSoup用法(1)
- beautifulsoup的简单用法
- beautifulsoup的简单用法
- Beautifulsoup的用法
- BeautifulSoup的详细用法
- BeautifulSoup的基本用法
- Python:第三方模块BeautifulSoup的安装及简单用法
- python BeautifulSoup的安装
- Python的BeautifulSoup安装
- BeautifulSoup库的用法详解
- python简单爬虫 及 beautifulSoup简单用法
- python BeautifulSoup模块的安装
- Python 下的BeautifulSoup 库
- Dagger2关键字之注解
- prompt(1) to win -----XSS学习笔记
- io流
- Unity中Invoke和InvokeRepeating
- 生活在孤独的思考中走过
- python的BeautifulSoup用法
- 上传jar包到nexus私服
- JavaScript变量、作用域和内存问题
- 单例
- 第十一天总结
- 编写windbg调试器扩展 入门篇2
- Sampled Softmax
- MVC三层架构简析
- 【bzoj3173】[Tjoi2013]最长上升子序列 Treap