CSS -- Python爬虫常用CSS选择器(Selectors)
其他
2018-06-24 18:13:15
阅读次数: 2
CSS – Python爬虫常用CSS选择器(Selectors)
selector |
example |
description |
.class |
.your_class |
选择所有class="your_class" 的元素 |
#id |
#name |
选择所有id="name" 的元素 |
* |
* |
选择所有的元素 |
element |
p |
选择所有的<p> 元素 |
element,element |
div,p |
选择所有的<div> 和<p> 元素 |
elment element |
div p |
选择所有的div 元素下所有的<p> 元素 |
elment>element |
div>p |
选择父元素为<div> 元素的所有<p> 元素 |
elment+element |
div+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> 元素 |
转载自blog.csdn.net/sino_crazy_snail/article/details/80140309