<p>我想这就是你要找的。它查找父p元素,将soup对象转换为字符串,删除strong元素,然后将字符串转换回soup对象</p>
<pre><code>from bs4 import BeautifulSoup
soup = BeautifulSoup("<p><strong>High School Honors: </strong><em>Parade </em>All-American; <em>Chicago Sun-Times </em>Illinois Player of the Year honors; rushed for 2,100 yards and 31 TDs as a senior; led team to 14-0 record and Class 4A State Championship as a junior with 1,820 yards and 26 TDs; also lettered in baseball.</p>", 'html.parser')
headerList = []
infoList = []
for strong_tag in soup.findAll('strong'):
parent = strong_tag.find_parent('p')
content = str(parent).replace(f'{strong_tag}', '')
souped_content = BeautifulSoup(content, 'html.parser')
infoList.append(souped_content)
headerList.append(strong_tag)
print(headerList)
print(infoList)
</code></pre>
<p>这将产生以下结果:</p>
<pre><code>[<strong>High School Honors: </strong>]
[<p><em>Parade </em>All-American; <em>Chicago Sun-Times </em>Illinois Player of the Year honors; rushed for 2,100 yards and 31 TDs as a senior; led team to 14-0 record and Class 4A State Championship as a junior with 1,820 yards and 26 TDs; also lettered in baseball.</p>]
</code></pre>