from bs4 import BeautifulSoup
text='''
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang='eng'>Harry Potter</title>
<price>29.9</price>
</book>
<book>
<title lang='eng'>Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
'''
soup=BeautifulSoup(text)
#按标准输出
# print(soup.prettify)
#获取所有文字
# print(soup.get_text())
#tag 对象
tag=soup.title
# print(tag)
tag.name #标签name
tag.attrs #标签属性
tag['lang'] #某一属性
tag.string #获取文字
string='<p><!--注释note--></p>'
sp=BeautifulSoup(string)
# sp.p.string
# print(soup.find_all('title',{'lang':'eng'}))
# print(soup.find('title',lang='eng'))
# soup.book
# soup.book.contents
# for child in soup.book.children: #字节点
# print(child)
# for parent in soup.book.parent: #父节点
# print(parent)
# for parents in soup.book.parents: #所有父节点
# print(parents.name)
soup.title.next_sibling #下一个兄弟
soup.title.previous_sibling #上一个兄弟
for sibling in soup.title.next_siblings: #所有兄弟
print(sibling)