Пример #1
0
    def parse_item(self, response):
        data = data_extractor.extractItems(self, response, self.getters)
        try:
            print '\n\n\n\n\n',repr(data),'\n\n\n\n'
            worth = data_processor.extract_decimals(data['worth'])
            price = data_processor.extract_decimals(data['price'])
            savings = worth - price
            data['discount'] = (savings/worth)*100
        except:
            data['discount'] = None
        return data


        
Пример #2
0
 def validate_worth(self, item, spider):
     if item.get('worth',None):
         item['worth'] = data_processor.extract_decimals(item['worth'])
         if not item['worth']:
             item['worth'] = 0
     else:
         item['worth'] = 0 # free 
     return item
Пример #3
0
 def validate_bought(self, item, spider):
     if item.get('bought',None):
         try:
             item['bought'] = int(data_processor.extract_decimals(item['bought']))
         except:
             item['bought'] = 0
     else:
         item['bought'] = 0
     return item
Пример #4
0
 def validate_discount(self, item, spider):
     if item.get('discount',None):
         item['discount'] = data_processor.extract_decimals(item['discount'])
         if not item['discount']:
             item['discount'] = 0
         return item
     else:
         item['discount'] = 0
     return item
Пример #5
0
def extractNumericXpath(hxs,xpath,index=None):
    return data_processor.extract_decimals(extractXpath(hxs,xpath,index))