используя регулярное выражение, вы можете получить классы, которые содержат подстроку "review"
.
import re
for container in containers:
title = container.findAll(a).text #This gives me titles
review = container.findAll("div", {"class": re.compile(r'review')})
См. Разницу:
html = '''<div class="review positive" title="" style="background-color: #00B551;">9.3</div>
<div class="review negative" title="" style="background-color: #FF0000;">4.8</div>
<div class="review neutral" title="" style="background-color: #FFFF00;">6</div>'''
from bs4 import BeautifulSoup
import re
soup = BeautifulSoup(html, 'html.parser')
review = soup.find_all('div', {'class':'review '})
print ('No regex: ',review)
print('\n')
review = soup.findAll("div", {"class": re.compile(r'review')})
print ('Regex: ',review)
Выход:
No regex: []
Regex: [<div class="review positive" style="background-color: #00B551;" title="">9.3</div>, <div class="review negative" style="background-color: #FF0000;" title="">4.8</div>, <div class="review neutral" style="background-color: #FFFF00;" title="">6</div>]