美文网首页
Selector选择器

Selector选择器

作者: 一只会循环的松鼠 | 来源:发表于2018-05-12 21:48 被阅读0次

Selector:

位置scrapy根目录下的selector文件中的unified(统一的).py中,

记得在装Scrapy之前会装许多依赖包,Selector继承了parsel文件下的selector.py中的Selector类

>>>def __init__(self, response=None, text=None, type=None, root=None, _root=None, **kwargs):

基本使用:

>>>Selector(response=response).xpath('  ')#.xpath()及.css()方法返回一个类SelectorList的实例, 它是一个新选择器的列表。这个API可以用来快速的提取嵌套数据。

为了提取真实的原文数据,你需要调用.extract()方法如下:

>>> response.xpath('//title/text()').extract()

[u'Example website']

于在response中使用XPath、CSS查询十分普遍,因此,Scrapy提供了两个实用的快捷方式:response.xpath()及response.css()

相关文章

网友评论

      本文标题:Selector选择器

      本文链接:https://www.haomeiwen.com/subject/zonhdftx.html