CSS selectors
single class first match
soup.select_one('.stylelistrow')
list of matches
soup.select('.stylelistrow')
compound class (i.e. AND another class)
soup.select_one('.stylelistrow.otherclassname')
soup.select('.stylelistrow.otherclassname')
Spaces in compound class names e.g. class = stylelistrow otherclassname
are replaced with ".". You can continue to add classes.
list of classes (OR - match whichever present)
soup.select_one('.stylelistrow, .otherclassname')
soup.select('.stylelistrow, .otherclassname')
bs4 4.7.1 +
Specific class whose innerText
contains a string
soup.select_one('.stylelistrow:contains("some string")')
soup.select('.stylelistrow:contains("some string")')
N.B.
soupsieve 2.1.0 + Dec'2020 onwards
NEW: In order to avoid conflicts with future CSS specification
changes, non-standard pseudo classes will now start with the :-soup-
prefix. As a consequence, :contains() will now be known as
:-soup-contains(), though for a time the deprecated form of
:contains() will still be allowed with a warning that users should
migrate over to :-soup-contains().
NEW: Added new non-standard pseudo class :-soup-contains-own() which
operates similar to :-soup-contains() except that it only looks at
text nodes directly associated with the currently scoped element and
not its descendants.
Specific class which has a certain child element e.g. a
tag
soup.select_one('.stylelistrow:has(a)')
soup.select('.stylelistrow:has(a)')