How to select values between two nodes in BeautifulSoup and Python?

You can select elements between two nodes in BeautifulSoup by looping through the main nodes, and checking the next siblings to see if a main node was reached: 

from bs4 import BeautifulSoup

html_content = '''
<h1>Starting Header</h1><p>Element 1</p><p>Element 2</p><p>Element 3</p><h1>Ending Header</h1>
'''
soup = BeautifulSoup(html_content, 'html.parser')

elements = []
for tag in soup.find("h1").next_siblings:
    if tag.name == "h1":
        break
    else:
        elements.append(tag)

print(elements)
# Output: [<p>Element 1</p>, <p>Element 2</p>, <p>Element 3</p>]

Related BeautifulSoup web scraping questions: