下面的操作产生一个列表:
xpath('.//div[@class="static"]/text()')
我想返回一个字符串而不是
我试着:
xpath('string-join(.//div[@class="static"]/text(), " ")')
和
xpath('.//div[@class="static"]/string-join(text(), " ")')
都是无效的,我做错了什么?
您有两个选择:
- 使用
'n'.join(response.css("div.static::text").extract())
在项目加载器中使用处理器:如果你经常使用它,这是迄今为止最优雅的解决方案:http://doc.scrapy.org/en/latest/topics/loaders.html.