find_all()
find_all( name , attrs , recursive , string , **kwargs )
返回一个列表类型,存储查找的结果
name : 对标签名称的检索字符串:
>>> import requests
>>> r=requests.get("http://python123.io/ws/demo.html")
>>> demo = r.text
>>> soup = BeautifulSoup(demo,'html.parser')
>>> soup.find_all('a')
[<a class="py1" href="http://www.icourse163.org/course/BIT-268001" id="link1">Basic Python</a>, <a c
lass="py2" href="http://www.icourse163.org/course/BIT-1001870001" id="link2">Advanced Python</a>]
>>> soup.find_all(['a','b'])
[<b>The demo python introduces several python courses.</b>, <a class="py1" href="http://www.icourse163.org/course/BIT-268001" id="link1">Basic Python</a>, <a class="py2" href="http://www.icourse163.org/course/BIT-1001870001" id="link2">Advanced Python</a>]
>>> for tag in soup.find_all(True):
... print(tag.name)
...
html
head
title
body
p
b
p
a
a
>>> import re
>>> for tag in soup.find_all(re.compile('b')):
... print(tag.name)
...
body
b
attrs: 对标签属性值的检索字符串,可标注属性检索:
>>> soup.find_all(

589

被折叠的 条评论
为什么被折叠?



