1

I have searched around to find about how to find a class with name contains some word but I don't find it. I want to take the information from class named with word footer on it.

<div class="footerinfo"> <span class="footerinfo__header"> </span> </div>

<div class="footer">
    <div class="w-container container-footer">
    </div>
</div>

I have tried this but it still don't work

soup.find_all('div',class_='^footer^'):

and

 soup.find_all('div',class_='footer*'):

Does anyone have any idea on doing this?

JasonC
  • 41
  • 1
  • 6

1 Answers1

1

You can use CSS selectors which allow you to select elements based on the content of particular attributes. This includes the selector *= for contains.

for ele in soup.select('div[class*="footer"]'):
    print (ele)

or regex

import re

regex = re.compile('.*footer.*')
soup.find_all("div", {"class" : regex})
chitown88
  • 24,774
  • 3
  • 26
  • 56