from bs4 import BeautifulSoup
# Example 1
html1 = '''
<img src="image1.jpg" alt="First image">
<p>Lorem ipsum 1 text between any two img tags</p>
<img src="image2.jpg" alt="Second image">
'''
soup1 = BeautifulSoup(html1, 'html.parser')
text1 = soup1.find('p').text
print(text1)
# Example 2
html2 = '''
<img src="photo1.png" alt="Photo 1">
<div>Lorem ipsum 2 text between any two img tags</div>
<img src="photo2.png" alt="Photo 2">
'''
soup2 = BeautifulSoup(html2, 'html.parser')
text2 = soup2.find('div').text
print(text2)
# Example 3
html3 = '''
<div class="wrap">
<img src="picture1.gif" alt="GIF Image 1">
Lorem ipsum 3 text between any two img tags
<img src="picture2.gif" alt="GIF Image 2">
</div>
'''
soup3 = BeautifulSoup(html3, 'html.parser')
div_wrap = soup3.find('div', class_='wrap')
# Remove the img tags
for img in div_wrap.find_all('img'):
img.decompose()
# Get the text of the div and strip leading/trailing whitespace
text3 = div_wrap.get_text(strip=True)
print(text3)