Web Scraping with Python Learning CHAPTER2 Advaced HTML Parsing

bs.find_all and bs.find

from bs4 import BeautifulSoup

bs.find_all(tag, attributes, recursive, text, limit, keywords)

bs.find(tag, attributes, recursive, text, keywords)

tag

bs,find_all(['h1', 'h2', 'h3'])  相互之间是“或”关系

attributes

bs.find_all('span', {'class': {'green', 'red'}})

recursive

是否递归遍历。如果为false,则只会匹配出现的第一个结果,默认true

text

bs,find_all(text='...') 完全匹配

limit

只对find_all有效,限制查询结果数量

keywords

bs.find_all('div', {'class':'green'})

其他的BS对象

BeautifulSoup库中有4种对象:

BS object

Tag object

bs.h1

NavigableString object

Comment object

<!--like this one-->.

Navigating Trees

children  and descendants

all children are descendants, but not all descendants are children

siblings

next_siblings()/next_sibling()

previous_siblings()/previous_sibling()

parents

.parent

,parents

Regular Expression

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值