Imagine you have the following HTML:
<div>
<label>Name:</label>
John Smith
</div>
And you need to locate the text “John Smith” after the label
element.
In this case, you can locate the label
element by text and then use [.next_sibling
property](https://www.crummy.com/software/BeautifulSoup/bs4/doc/#next-sibling-and-previous-sibling):
from bs4 import BeautifulSoup
data = """
<div>
<label>Name:</label>
John Smith
</div>
"""
soup = BeautifulSoup(data, "html.parser")
label = soup.find("label", text="Name:")
print(label.next_sibling.strip())
Prints John Smith
.