scrapy shell https://doc.scrapy.org/en/latest/_static/selectors-sample1.html
- response.xpath('//title/text()')
- response.css('title::text')
- 提取第一个匹配的元素
- response.xpath('//div[@id="images"]/a/text()').extract_first()
- 嵌套选择器
- response.xpath('//a[contains(@href, "image")]')
- 通过正则表达式来提取数据
- response.xpath('//a[contains(@href, "image")]/text()').re(r'Name:\s*(.*)')
- response.xpath('//a[contains(@href, "image")]/text()').re_first(r'Name:\s*(.*)')
- 注意 //node[1] 和 (//node)[1] 的区别
- //node[1] 选择在其各自父节点下首先出现的所有 node。
- (//node)[1] 选择文档中的所有 node,然后只获取其中的第一个节点。
401

被折叠的 条评论
为什么被折叠?



