Python爬虫(bs4)-2
来源:互联网 发布:淘宝拍下返现送小礼物 编辑:程序博客网 时间:2024/06/06 09:34
本文基于书籍《Python网络数据采集》(Web Scraping with python)
语言:python3
系统:CentOS7
python库:Beautiful Soup4
1.抽取HTML中标签属性
在BeautifulSoup中使用findAll()/final()函数
findAll(tag,attribute,recursive,text,limit,keywords)
tag: 标签名或者标签名组成的标签列表
attribute:由字典组织的{ “属性名” : {“属性值”,……..}}
recursive: 布尔值 ture 查找所有子标签(默认)/false 仅查找一级
text : findAll(text = “XXXXX”) 返回含有“”XXXX“文本内容的标签
limit : findAll(limit=x)显示前x项,x=1为find()函数
keywords:findALL(id = “属性名”)返回含有此属性名标签
2.标签方法
标签对象.get_text()
返回标签内容且无标签
标签对象.attrs
返回此标签下所有属性(以字典的数据结构)
标签对象.attrs["属性名"]
返回指定属性名的属性值
3.处理标签树
由于利用BeautifulSoup将HTML/XML变为树形结构,可以进行树的逻辑处理
1.子标签
bsObj.find(xxxxxx).chidren
find(XXXXX)为寻找指定标签
2.兄弟标签
bsObj.find(xxxxxx).next_siblings
此标签之后所有兄弟标签
bsObj.find(xxxxxx).previous_siblings
一组兄弟标签最后一个标签
3.父标签
bsObj.find(xxxxxx).parent
直接父标签
bsObj.find(xxxxxx).parents
逻辑上所有夫标签
4.下载文件
利用urllib中的模块
from urllib.request import urlretrieveurlretrieve(url,"文件夹名")
将URL指定内容侠盗指定文件夹中
0 0
- Python爬虫(bs4)-2
- Python爬虫(bs4)-1
- Python爬虫(bs4)-3
- Python爬虫之bs4库
- Python -bs4反爬虫解决方法
- Python爬虫(urllib2+bs4)+分析找出谁是水贴王(2)--数据分析
- requests和bs4的python爬虫入门
- 爬虫笔记2(转)BS4库的解析器
- Python爬虫(urllib2+bs4)+分析找出谁是水贴王(1)--数据收集
- [Python 爬虫之路1] 爬取糗事百科(requests,bs4)
- [Python]BS4 与 一个KDS 美图爬虫
- Python网络爬虫requests、bs4爬取空姐网图片
- 从零开始写Python爬虫 --- 1.3 BS4库的解析器
- python爬虫笔记day1 BS4库的使用
- 爬虫Selenium&bs4 + Miku分享
- 爬虫系列10.BS4简介
- python——爬虫学习——基于bs4库的HTML内容查找方法-(3)
- 【python爬虫小实战】python3.x用requests和bs4实现有道翻译(中英文)
- Leetcode 58. Length of Last Word
- activemq 详解
- php 运行时配置
- 使用pageConetxt.getattribute获得来自pageContxet.setattribute的值的问题。花了很多时间
- ViewPage动态删除页面
- Python爬虫(bs4)-2
- springmvc整合mybatis分页代码示例
- 《APP程序的启动原理》
- ASP.NET MVC中的cshtml页面中的下拉框的使用
- Linux 安装mysql 5.7.14 版
- I finally figured out weakSelf and strongSelf
- POJ1004 && Financial Management
- shell脚本——流程控制的操作使用
- block要用copy修饰,还是用strong