Hi,
from bs4 import BeautifulSoup
html = '<p>This <i>is</i> a test.</p>'
soup = BeautifulSoup(html, 'lxml')
print(soup)
for tag in soup.find_all('i'):
tag.replace_with('is')
print(soup)
print("\n")
print(soup.prettify())
print("\n")
for string in soup.stripped_strings:
print(string)
This programs outputs the following:
<html><body><p>This <i>is</i> a test.</p></body></html>
<html><body><p>This is a test.</p></body></html>
<html>
<body>
<p>
This
is
a test.
</p>
</body>
</html>
This
is
a test
Why though?
Why is the string still splitted in three parts as if the removed tag was still present?
If I use <p>This is a test.</p> (which is the output after I replaced the tag) as my starting html everything is working fine.
What am I doing wrong?
Thanks in Advance