在BeautifulSoup中,findAll()方法已经被deprecated(不再推荐使用),推荐使用find_all()方法代替。find_all()方法返回一个ResultSet对象,包含了所有匹配的标签。如果要显示每个标签,可以使用循环遍历ResultSet对象。
以下是一个示例代码:
from bs4 import BeautifulSoup
html_doc = """
BeautifulSoup Example
BeautifulSoup Example
This is an example of BeautifulSoup.
- Item 1
- Item 2
- Item 3
"""
# 创建BeautifulSoup对象
soup = BeautifulSoup(html_doc, 'html.parser')
# 使用find_all()方法查找所有的li标签
items = soup.find_all('li')
# 遍历ResultSet对象,显示每个标签的内容
for item in items:
print(item.text)
以上代码输出结果为:
Item 1
Item 2
Item 3
这样就可以显示每个标签的内容了。请注意,这里使用的是find_all()方法,而不是findAll()方法。