Xpath:为什么normalize-space无法删除空白和\ n?

Lea*_*AWK 5 xpath scrapy-spider

对于以下代码:

<a class="title" href="the link">
Low price
<strong>computer</strong>
you should not miss
</a>
Run Code Online (Sandbox Code Playgroud)

我使用此xpath代码进行抓取:

response.xpath('.//a[@class="title"]//text()[normalize-space()]').extract()
Run Code Online (Sandbox Code Playgroud)

我得到以下结果:

u'\n                  \n                  Low price ', u'computer', u' you should not miss'
Run Code Online (Sandbox Code Playgroud)

为什么\n在此示例中low price没有删除之前的两个空白空间normalize-space()

另一个问题:如何将这三个零件合并为一个刮板u'Low price computer you should not miss'

Ale*_*rov 5

请尝试以下方法:

'normalize-space(.//a[@class="title"])'
Run Code Online (Sandbox Code Playgroud)