from bs4 import BeautifulSoup
html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><b>The Dormouse's story</b></p>
<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>
<p class="story">...</p>
"""
soup = BeautifulSoup(html_doc)
#输出soup对象中所有标签名为"title"的标签print(soup.findAll("title"))
#输出soup对象中所有标签名为"title"和"a"的标签print(soup.findAll({"title","a"}))
#输出soup对象中所有属性为"class"属性值为“sister”的标签print(soup.findAll("",{"class" : "sister"}))
#输出soup对象中所有属性为"id"属性值为“link1”的标签print(soup.findAll("",{"id":"link1"}))
#输出soup对象中所有属性为“class”属性值为“story”或“title”或“sister”的标签print(soup.findAll("",{"class":{"story","title","sister"}}))
#输出soup对象中包含“The Dormouse's story”内容的标签数量(通过文本参数text)print(len(soup.findAll("",text = "The Dormouse's story")))
#输出soup对象中所有属性为"id"属性值为“link1”的标签(通过关键字参数keyword)print(soup.findAll("",id = "link1"))
#输出soup对象中所有属性为"class"属性值为“sister”的标签(通过关键字参数keyword)print(soup.findAll("",class_ = "sister"))