Python的Beautiful Soup学习笔记
来源:互联网 发布:统计学,概率论软件 编辑:程序博客网 时间:2024/05/17 16:12
参考文章
# 安装好Python, 之后再安装bs4和lxml解析器>>>pip install bs4>>>pip install lxml
# -*- coding=utf8 -*-from bs4 import BeautifulSoup# 用lxml解析html这个文档soup = bs4(html, 'lxml')# 查找第一个出现的a标签soup.find("a")# 查找所有a标签, 返回值为列表soup.find_all("a")# 获取所有文件内容soup.get_text()# 获取a标签内class属性tag_a = soup.find("a")tag_a["class"]# 获取a标签内的文字内容tag_a = soup.find("a")tag_a.string# 可以直接转换为unicode字符串unicode(tag_a.string)# 加入正则表达式import re # 找出所有含a的标签soup.find_all(re.compile("a"))# 找出所有含a、b标签soup.find_all(["a", "b"])# 详解find_all()# 找出所有p标签中含有title属性的内容soup.find_all("p", "title")# 找出所有href属性符合这个正则表达式且id="link1"的内容import re soup.find_all(href=re.compile("elsie"), id="link1")# 找出所有a标签中有class为sister的内容,由于python含有class这个类名,产生冲突所以需要改成class_soup.find_all("a", class_="sister")# 找到所有a标签,限制返回列表的个数为2soup.find_all("a", limit=2)
阅读全文
0 0
- Python的Beautiful Soup学习笔记
- 【python学习笔记】10:Beautiful Soup模块的使用
- python爬虫-Beautiful Soup学习笔记
- Beautiful Soup-学习笔记
- python Beautiful Soup的用法
- Python语言学习:Beautiful Soup四个对象的具体用法
- Python爬虫入门-Beautiful Soup的用法
- Python爬虫利器Beautiful Soup的用法
- python beautiful soup库的用法
- 六.Python爬虫Beautiful Soup的用法
- python Beautiful Soup文档
- Python Beautiful Soup简介
- Python Beautiful Soup Example
- [Python]安装Beautiful Soup
- python 安装 Beautiful Soup
- Python模块Beautiful Soup
- Beautiful Soup学习
- 【python学习笔记】8:网页解析器及安装Beautiful Soup 4
- 知识图谱2-【浅谈知识图谱的构建技术】
- anaconda安装pyqt
- jedis入门
- JS 读取本地文件
- 立体匹配算法:《Cross-Scale Cost Aggregation for Stereo Matching》总结
- Python的Beautiful Soup学习笔记
- 持续集成之jenkins实践教程:基础篇(4): 集成redmine
- LeetCode-121. Best Time to Buy and Sell Stock (Java)
- dbms_space.create_table_cost的unwrap解密和原理解析
- SVN报错Cleanup failed to process the following paths
- Struts2系列登录注册的小项目之验证规则
- HTML <option> 标签的 value 属性
- React-Native 发送和接收事件DeviceEventEmitter
- MediaPlayer实现音乐文件的边下边播