Python爬虫CSS选择器

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

selector    example     description
.class    .your_class     选择所有class="your_class"的元素
#id        #name  选择所有id="name"的元素
*        * 选择所有的元素
element   选择所有的<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>元素

 转载自:Sino_Crazy_Snail 

猜你喜欢

转载自blog.csdn.net/Hubz131/article/details/88857643
今日推荐