标签:not store name learning tag lan att tor learn
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‘] #某一属性
print(tag.string) #获取文字
string=‘<p><!--注释note--></p>‘
sp=BeautifulSoup(string)
sp.p.string
标签:not store name learning tag lan att tor learn
原文地址:https://www.cnblogs.com/tiankong-blue/p/11610040.html