How to fix?
You can solve your issue by using css selectors
that looks if class
contains your substring:
soup.select_one('div[class*="carrier-text"]')
Please note
It will work for your specific example, but take care if there are elements with class
that also contains your substring, then you may have to select more specific.
Options
Cause your question is not that clear - Extracting the text
or the class
?
Get the text
soup.select_one('div[class*="carrier-text"]').get_text(strip=True)
Get the class
soup.select_one('div[class*="carrier-text"]')['class']
Example
html = """
<div class="dErF-carrier-text">
Alaska Airlines 398 </div>
"""
soup = BeautifulSoup(html, 'html.parser')
soup.select_one('div[class*="carrier-text"]').get_text(strip=True)
Output
Alaska Airlines 398