要解决这个问题,可以按照以下步骤使用BeautifulSoup方法:
from bs4 import BeautifulSoup
html = 'Example
BeautifulSoup Example
'
soup = BeautifulSoup(html, 'html.parser')
# 找到第一个标签,并打印其文本内容
h1_tag = soup.find('h1')
print(h1_tag.text)
# 找到所有的
标签,并打印其文本内容
p_tags = soup.find_all('p')
for p in p_tags:
print(p.text)
这样,你就可以使用BeautifulSoup方法来解析HTML文档并提取所需的内容了。