1

I'm following the documentation about serializers in this link, I'm not sure if there's lack of documentation regarding on decimal serializers ?. I defined an Item with a scrapy field like this:

prize = scrapy.Field(serializer=Decimal, output_processor=TakeFirst())

I'm getting several errors when scrapinhub stores this value, especially with numbers containing commas.

Is there any standard method for serializing decimals?

delpo
  • 210
  • 2
  • 18

1 Answers1

3

This is not a scrapinghub, or scrapy error, you cannot convert a strings with comma into a number, you'll first have to remove that comma and then convert:

def decimal_serializer(value):
    return float(value.replace(',', ''))

...

    prize = scrapy.Field(serializer=decimal_serializer, output_processor=TakeFirst())
eLRuLL
  • 18,488
  • 9
  • 73
  • 99