I have the following HTML document,
html_part = '''
<h3>First Header</h3>
First Header Content
<h3>Second Header</h3>
Second Header with some annoying tag </br>
which ruins the extraction </br>
<h3>Third Header</h3>
This works fine
'''
And I am trying to extract all the content between the h3 tags with the following program,
from bs4 import BeautifulSoup
soup = BeautifulSoup(
html_part,
'html.parser'
)
for index in soup.find_all('h3'):
print(
index.next_sibling.string
)
print("-")
Which gives the following output,
First Header Content
-
Second Header with some annoying tag
-
This works fine
-
My desired output is the following,
First Header Content
-
Second Header with some annoying tag </br>
which ruins the extraction </br>
-
This works fine
-
How do I proceed?