CSS选择器
单班第一场比赛
soup.select_one('.stylelistrow')
匹配列表
soup.select('.stylelistrow')
复合类(即与另一个类)
soup.select_one('.stylelistrow.otherclassname')
soup.select('.stylelistrow.otherclassname')
复合类名中的空格,例如class = stylelistrow otherclassname被替换为"."。您可以继续添加类。
类列表(OR -匹配当前的任何一个)
soup.select_one('.stylelistrow, .otherclassname')
soup.select('.stylelistrow, .otherclassname')
类属性,其值包含一个字符串,例如"stylelistrow":
以“style”开头:
[class^=style]
以row结尾
[class$=row]
包含“列表”:
[class*=list]
^, $和*是操作符。更多信息请点击:https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors
如果你想排除这个类,那么,以anchor tag为例,选择没有这个类的anchor tags:
a:not(.stylelistrow)
你可以在:not()伪类中传递简单、复合和复杂的css选择器列表。见https://facelessuser.github.io/soupsieve/selectors/pseudo-classes/:不是
Bs4 4.7.1 +
innerText包含字符串的特定类
soup.select_one('.stylelistrow:contains("some string")')
soup.select('.stylelistrow:contains("some string")')
N.B.
汤式饮料2.1.0 + 2020年12月
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.
具有特定子元素的特定类,例如标签
soup.select_one('.stylelistrow:has(a)')
soup.select('.stylelistrow:has(a)')