CSS – Python爬虫常用CSS选择器(Selectors)

selector   example    description
.class   .your_class    选择所有class="your_class"的元素
#id       #name 选择所有id="name"的元素
*       *选择所有的元素
element  选择所有的<p>元素
element,elementdiv,p  选择所有的<div>和<p>元素
elment element div p    选择所有的div元素下所有的<p>元素
elment>element   div>p    选择父元素为<div>元素的所有<p>元素
elment+elementdiv+p  选择紧接在<div>元素之后的所有<p>元素
element~element    p~ul选择前面有<p>元素的每个<ul>元素
[attribute]  [href] 选择带有href属性的所有元素
[attribute=value]  [href=#] 选择href=#的所有元素
[attribute~=value]      [title~=python]  选择title属性包含字符串python的所有元素
[attribute|=value]       [lang|=en]选择lang属性值以"en"开头的所以元素
[attribute^=value]    a[src^="https"]   选择src属性值以"https"开头的每个<a>元素
[attribute$=value]    a[src$=".jpg"    选择src属性值以".jpg"结尾的每个<a>元素
[attribute*=value]    a[src*="image"  选择src属性值包含字符串"image"的每个<a>元素

 转载自:Sino_Crazy_Snail 

更多推荐

Python爬虫CSS选择器