Selector中的css选择器

返回的数据

返回response的方法:
一般是利用requests的get方法
得到放回的response有如下几个属性:
Status_code: http放回的状态码200表示成功,404表示未找到
Text:相应内容的字符串形式。url对应的页面内容
Encoding:从HTTP header中猜测相应的内容编码方式
Headers:http相应内容的头部内容

**

css选择器的实例

**
quote.css (’ .text ’)
[<Selector xpath=”descendant-or-self: :[@class and contains(concat(’’, normalize space(@class),”),
’ text ’ )] ” data=’<span class=’<span class=”text ” itemprop=”text ” 〉“The ’ 〉 ]
理解:如果只选择class为text 的话那么css选择器会返回第一个class为text 的标签,并返回所有的属性

quote . css (’. text: : text’ )
[<Selector xpath="descendant-or-self:: *[@class and contains(concat(’’, normalize-space(@class), '’), ’ text’ ) ]/text() " data=’“The world as we have created it is a pr ’>]
理解:返回标签的性质和对应的正文

quote . css ( ’ .text ’) . extract()
[’<span class=”t ext " itemprop=“text”>“The world as we have created it is a process our our thinking. It cannot be changed without changing our thinking /span > ’ )
理解:返回标签的所有属性和正文

quote. css (’. text: : text ’) . extract()
[ ’”The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking. ”’]
理解:返回一个列表这个列表含有正文内容

quote . css ( ’. text: : text ’) . extract_ first()
”The world as we have created it is a process of our thinking . It cannot be changed without changing our thin
理解:返回列表的第一个内容

猜你喜欢

转载自blog.csdn.net/qq_42224330/article/details/88722739