I want to select all <div>
where class name is either post has-profile bg2
OR post has-profile bg1
but not last one i.e. panel
<div id="6" class="post has-profile bg2"> some text 1 </div>
<div id="7" class="post has-profile bg1"> some text 2 </div>
<div id="8" class="post has-profile bg2"> some text 3 </div>
<div id="9" class="post has-profile bg1"> some text 4 </div>
<div class="panel bg1" id="abc"> ... </div>
select()
is matching only single occurrence. I'm trying it with find_all()
, but bs4 is not able to find it.
if soup.find(class_ = re.compile(r"post has-profile [bg1|bg2]")):
posts = soup.find_all(class_ = re.compile(r"post has-profile [bg1|bg2]"))
How to solve it with regex and without regex? Thanks.