I can't seem to find out how to search for classes that contains a specific string i.e. searching for the class "Header" would return both the class "This-Header" and "Header-that".
Anyone got a workable solution to this?
I can't seem to find out how to search for classes that contains a specific string i.e. searching for the class "Header" would return both the class "This-Header" and "Header-that".
Anyone got a workable solution to this?
You can pass callables and regular expressions as the class_
keyword argument:
import re
soup.find('a', class_=re.compile(r'Header'))
Or:
soup.find('a', class_=lambda c: 'Header' in c)
Both of these will match <a class="Test-Headers"></a>
, so you'll have to adjust them if that's not behavior you want.