Perhaps you can use a regular expression.
If you are using the selector use the .re method:
>>> sel.xpath('//*[@class="priceright
secondarytextbold"]/text()').re("\d+\.\d+")
[u'117.95']
If you are using an item loader use the re argument:
loader.add_xpath('price', '//*[@class="priceright
secondarytextbold"]/text()', re='\d+\.\d+')
See the following links for more information:
http://docs.python.org/2/howto/regex.html
http://doc.scrapy.org/en/latest/topics/selectors.html#using-selectors-with-regular-expressions
http://doc.scrapy.org/en/latest/topics/loaders.html#scrapy.contrib.loader.ItemLoader.add_xpath
http://www.regular-expressions.info/quickstart.html
Rolando
On Wed, Feb 12, 2014 at 10:37 PM, BrendanB <[email protected]> wrote:
> Hi,
>
> I have a price field which includes some text. I would like to exclude
> anything but the price. I have tried the following to no avail.
>
> <span class="priceright secondarytextbold">$117.95 per item</span>
>
> Here is my current xpath, which works fine in firebug, however if there is
> no additional text, it bombs out with null. How would I handle a condition
> like this?
>
> substring-before(.//*[@class='priceright secondarytextbold']/text(),' ')
>
>
> Regards,
> Brendan
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "scrapy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/scrapy-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"scrapy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/scrapy-users.
For more options, visit https://groups.google.com/groups/opt_out.