
如:soup.title
#
soup.p
#
The Dormouse's story
soup.a(注:仅仅返回第一个结果)

# Elsie
soup.find_all('a') (find_all 可以返回所有)
# [Elsie,
# Lacie,
# Tillie]
find还可以按属性查找

soup.find(id="link3")
# Tillie
要取某个标签的某个属性beautifulsoup怎么用,可用变量有 find_all,get
for link insoup.find_all('a'):
print(link.get('href'))
#

#
#
要取html文件中的所有文本beautifulsoup怎么用,可使用get_text()
print(soup.get_text())
# TheDormouse's story
# TheDormouse's story

# Once upona time there were three little sisters; and their names were
#Elsie,
# Lacieand
#Tillie;
# and theylived at the bottom of a well.
# ...
如果是打开html文件,语句可用:
soup =BeautifulSoup(open("index.html"))
BeautifulSoup中的Object
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-144654-1.html
对中国大部分地区来说问题不是环保
文化上