From 77984bf5fe6a18e2bf39edc8f78b74f5699820c3 Mon Sep 17 00:00:00 2001 From: Vicnet Date: Thu, 20 Feb 2014 17:19:05 +0100 Subject: [PATCH] Fix pagination Signed-off-by: Vicnet --- modules/lacentrale/backend.py | 7 +++++-- modules/lacentrale/browser.py | 3 +-- modules/lacentrale/pages.py | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/lacentrale/backend.py b/modules/lacentrale/backend.py index 66a40d7b..f7b7a486 100644 --- a/modules/lacentrale/backend.py +++ b/modules/lacentrale/backend.py @@ -39,10 +39,13 @@ class LaCentraleBackend(BaseBackend, ICapPriceComparison): BROWSER = LaCentraleBrowser # inherited from ICapPriceComparison - def search_products(self, patterns=None): + def search_products(self, patternString=None): # convert pattern to criteria criteria = { } - for pattern in patterns.split(','): + patterns = [] + if patternString: + patterns = patternString.split(',') + for pattern in patterns: pattern = pattern.lower() if u'€' in pattern: criteria['maxprice'] = pattern[:pattern.find(u'€')].strip() diff --git a/modules/lacentrale/browser.py b/modules/lacentrale/browser.py index cb64150a..6f26c465 100644 --- a/modules/lacentrale/browser.py +++ b/modules/lacentrale/browser.py @@ -37,7 +37,6 @@ class LaCentraleBrowser(BaseBrowser): 'http://www.lacentrale.fr/': MainPage, 'http://www.lacentrale.fr/listing_auto.php?.*': ListingAutoPage, } -#http://www.lacentrale.fr/listing_auto.php?witchSearch=0&SS_CATEGORIE=40&mo_comm=&Citadine=citadine=&km_maxi=120000&annee2=&conso=&co2=&opt=&version=&transmission=&couleur=&nbportes=%3D5&photo=&new_annonce=&cp=31&origine=1 def iter_products(self, criteria): if not self.is_on_page(MainPage): @@ -67,7 +66,7 @@ class LaCentraleBrowser(BaseBrowser): numpage = 1 while True: # parse the current page - for price in self.page.iter_prices(numpage): + for price in self.page.iter_prices(product, numpage): yield price # check if next page diff --git a/modules/lacentrale/pages.py b/modules/lacentrale/pages.py index 9ba94a7b..d6732e85 100644 --- a/modules/lacentrale/pages.py +++ b/modules/lacentrale/pages.py @@ -47,7 +47,7 @@ class ListingAutoPage(BasePage): return '' return td[-1].text_content().strip() - def iter_prices(self, numpage): + def iter_prices(self, product, numpage): for tr in self.document.getroot().cssselect('tr.lcline[id],tr.lclineJB[id],tr.lclineJ[id]'): id = '{numpage}.{id}'.format(numpage=numpage, id=tr.attrib['id'][3:]) title = self._extract(tr, 'lcbrand') @@ -63,9 +63,12 @@ class ListingAutoPage(BasePage): cost = ', ' + self._extract(tr, 'lcprice') price = Price(id) + price.product = product price.cost = Decimal(re.findall(r'\d+',cost.replace(' ',''))[0]) price.currency = u'€' price.message = unicode(title) + price.shop = Shop(price.id) + price.shop.set_empty_fields(NotAvailable) price.set_empty_fields(NotAvailable) yield price