无效的 XPath: string-join(.//div[@class= "static" ]/text(), " " )?



下面的操作产生一个列表:

xpath('.//div[@class="static"]/text()')

我想返回一个字符串而不是

我试着:

xpath('string-join(.//div[@class="static"]/text(), " ")')

xpath('.//div[@class="static"]/string-join(text(), " ")')

都是无效的,我做错了什么?

您有两个选择:

    使用
  1. 'n'.join(response.css("div.static::text").extract())
    
  2. 在项目加载器中使用处理器:如果你经常使用它,这是迄今为止最优雅的解决方案:http://doc.scrapy.org/en/latest/topics/loaders.html.

最新更新