Serialize decimals in scrapinghub

133 views Asked by At

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?

1

There are 1 answers

0
eLRuLL On BEST ANSWER

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())