BeautifulSoupで不要な文字列を削除する(decompose)

tsx
<h2>wanted<span class="aaa">www</span></h2>
python
h2 = soup.find('h2')
span = soup.find('span')
span.decompose()
print(h2.text) // wanted
python
h2 = soup.find('h2').text
span = soup.find('span')
span.decompose()
print(h2) // wanted www

関連記事