You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to set the price to 0.0 if the item is missing, for this I check if the xpath is empty in the price_in declaration within the ItemLoader-based class:
price_in=Compose(TakeFirst(), lambda _: float(_) if _ else 0)
But the value of zero isn't stored in the _values dict because of the following code in the scrapy/loaders/init.py:_add_value():
def _add_value(self, field_name, value):
value = arg_to_iter(value)
processed_value = self._process_input_value(field_name, value)
if processed_value:
self._values[field_name] += arg_to_iter(processed_value)
I don't know why the logic is like this, but it won't store neither zeros nor empty strings. Is it illegal? I use scrapy for about a week, so don't know the usage practices at all, but this seems strange to me.
Maybe change the condition to “processed_value is not None”?
The text was updated successfully, but these errors were encountered:
I'm scraping a eshop, there's a price xpath for an item's price, which is empty if the item is out of stock.
I use ItemLoader, and add_xpath():
item.add_xpath('price', './/span[@class="price rub"]/text()')
I want to set the price to 0.0 if the item is missing, for this I check if the xpath is empty in the price_in declaration within the ItemLoader-based class:
price_in=Compose(TakeFirst(), lambda _: float(_) if _ else 0)
But the value of zero isn't stored in the _values dict because of the following code in the scrapy/loaders/init.py:_add_value():
I don't know why the logic is like this, but it won't store neither zeros nor empty strings. Is it illegal? I use scrapy for about a week, so don't know the usage practices at all, but this seems strange to me.
Maybe change the condition to “processed_value is not None”?
The text was updated successfully, but these errors were encountered: