I use String.join to pull out all the strings from a list:
>>> " ".join([' aaa ', u'bbb '])
u' aaa bbb '
and if you want to strip each element you can use Python's cool list
comprehension:
>>> " ".join(x.strip() for x in [' aaa ', u'bbb '])
u'aaa bbb'
and as Pablo pointed out, you can use a Scrapy processor:
>>> from scrapy.contrib.loader.processor import Join
>>> proc = Join()
>>> proc(x.strip() for x in [' aaa ', u'bbb '])
u'aaa bbb'
and if you have any blank items you can strip the final string as
well:
>>> proc(x.strip() for x in [u'\n\t\t', u'\n\t', u'\n\t\n\t\t\n\tMoto']).strip()
u'Moto'
On Jul 14, 4:07 pm,
scr...@asia.com wrote:
> Thanks for your answer.
>
> It's a solution that works, but when items are put together again there are some words merge together... after trim item by item...
>
> Example:
>
> u' aaa ', u'bbb ' => aaabbb and it should be: aaa bbb
>
> My code is:
>
> sequence = list(item['content'])
> i = 0
> while i < len(sequence):
> it = sequence[i]
> item['content'][i]=it.strip()
> i += 1
>
> what's about this normalize-space()? I can't use it?
>
> -----Original Message-----
> From: Rishi Singh <
rishisi...@gmail.com>
> To:
scrapy...@googlegroups.com
> Sent: Wed, Jul 14, 2010 3:11 pm
> Subject: Re: Trim xpath results
>
> Apologies, just .strip() every item in the returned results.
>