# 1、导入模块
from bs4 import BeautifulSoup
# 2、准备文档字符串
html='''
The Dormouse's story
The Dormouse's story
Once upon a time there were three little sisters; and their names were
Elsie,
Lacieand
Tillie;
and they lived at the bottom of a well.
...
'''
# 3、创建BeautifulSoup对象
soup=BeautifulSoup(html,'lxml')
# 一、根据标签进行查找
# 4、查找title标签
title=soup.find('title')
print(title)
# 5、查找a标签
a=soup.find('a')
print(a)
# 查找所有的a标签 结果会放到列表中进行展示
a_s=soup.findAll('a')
print(a_s)
# 二、根据属性进行查找
# 查找id为link1的标签
# 方式1:通过命名参数进行指定的
a=soup.find(id='link1')
print(a)
# 方式2:使用attrs来指定属性字典,进行查找
a=soup.find(attrs={'id':'link1'})
print(a)
# 三、根据文本内容进行查找 (此方法使用的少)
text=soup.find(text='Elsie')
print(text)
# Tag对象
print(type(a)) #
print('标签名',a.name)
print('标签所有属性',a.attrs)
print('标签文本内容',a.text)



