Beautiful Soup: Get a specific text that does not have a specific class

advertisements

I am trying to get the highlighted text "frei ab 01.05.2017" below. The problem is however, that the class "section_content iw_right" exists 19 times on that website. I would do a find_all and return only the 11th element from there, however on some sites that I want to scrape there are a different number of that class, so I might not always catch the right one. Any ideas? Thanks!


One way to get to the desired element is using the preceding label - locate the span element with "Erdgeschoss" text and find the next strong sibling:

label = soup.find("span", text="Erdgeschoss")
print(label.find_next_sibling("strong").get_text())