笨鸟编程-零基础入门Pyhton教程

 找回密码
 立即注册

选择器

发布者: 笨鸟自学网



SelectorList对象

classscrapy.selector.SelectorList(iterable=()/)[源代码]

这个 SelectorList 类是内置的子类 list 类,它提供了一些附加方法。

xpath(xpathnamespaces=None**kwargs)[源代码]

打电话给 .xpath() 此列表中的每个元素的方法,并将其结果扁平化为另一个 SelectorList .

query is the same argument as the one in Selector.xpath()

namespaces 是可选的 prefix: namespace-uri 将附加前缀的映射(dict)映射到 register_namespace(prefix, uri) . 相反 register_namespace() ,这些前缀不会保存以备将来调用。

可以使用任何其他命名参数来传递xpath表达式中xpath变量的值,例如::

selector.xpath('//a[href=$url]', url="http://www.example.com")
css(query)[源代码]

打电话给 .css() 此列表中的每个元素的方法,并将其结果扁平化为另一个 SelectorList .

query is the same argument as the one in Selector.css()

getall()[源代码]

打电话给 .get() 每个元素的方法都是这个列表,并将它们的结果作为一个Unicode字符串列表平展地返回。

参见: extract()和extract_first()。

get(default=None)[源代码]

返回的结果 .get() 对于此列表中的第一个元素。如果列表为空,则返回默认值。

参见: extract()和extract_first()。

re(regexreplace_entities=True)[源代码]

打电话给 .re() 方法,并以unicode字符串列表的形式返回结果。

默认情况下,字符实体引用替换为其相应的字符(除了 & 和 < .经过 replace_entities 作为 False 关闭这些替换。

re_first(regexdefault=Nonereplace_entities=True)[源代码]

打电话给 .re() 方法,并以Unicode字符串返回结果。如果列表为空或regex不匹配,则返回默认值 (None 如果未提供参数)。

默认情况下,字符实体引用替换为其相应的字符(除了 & 和 < .经过 replace_entities 作为 False 关闭这些替换。

attrib

返回第一个元素的属性字典。如果列表为空,则返回空的dict。

参见: 选择元素属性 .


上一篇:蜘蛛下一篇:项目

Archiver|手机版|笨鸟自学网 ( 粤ICP备20019910号 )

GMT+8, 2024-9-17 04:17 , Processed in 0.058911 second(s), 17 queries .

© 2001-2020

返回顶部