Fix pagination

Signed-off-by: Vicnet <vo.publique@gmail.com>
This commit is contained in:
Vicnet 2014-02-20 17:19:05 +01:00 committed by Florent
commit 77984bf5fe
3 changed files with 10 additions and 5 deletions

View file

@ -39,10 +39,13 @@ class LaCentraleBackend(BaseBackend, ICapPriceComparison):
BROWSER = LaCentraleBrowser BROWSER = LaCentraleBrowser
# inherited from ICapPriceComparison # inherited from ICapPriceComparison
def search_products(self, patterns=None): def search_products(self, patternString=None):
# convert pattern to criteria # convert pattern to criteria
criteria = { } criteria = { }
for pattern in patterns.split(','): patterns = []
if patternString:
patterns = patternString.split(',')
for pattern in patterns:
pattern = pattern.lower() pattern = pattern.lower()
if u'' in pattern: if u'' in pattern:
criteria['maxprice'] = pattern[:pattern.find(u'')].strip() criteria['maxprice'] = pattern[:pattern.find(u'')].strip()

View file

@ -37,7 +37,6 @@ class LaCentraleBrowser(BaseBrowser):
'http://www.lacentrale.fr/': MainPage, 'http://www.lacentrale.fr/': MainPage,
'http://www.lacentrale.fr/listing_auto.php?.*': ListingAutoPage, '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): def iter_products(self, criteria):
if not self.is_on_page(MainPage): if not self.is_on_page(MainPage):
@ -67,7 +66,7 @@ class LaCentraleBrowser(BaseBrowser):
numpage = 1 numpage = 1
while True: while True:
# parse the current page # parse the current page
for price in self.page.iter_prices(numpage): for price in self.page.iter_prices(product, numpage):
yield price yield price
# check if next page # check if next page

View file

@ -47,7 +47,7 @@ class ListingAutoPage(BasePage):
return '' return ''
return td[-1].text_content().strip() 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]'): 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:]) id = '{numpage}.{id}'.format(numpage=numpage, id=tr.attrib['id'][3:])
title = self._extract(tr, 'lcbrand') title = self._extract(tr, 'lcbrand')
@ -63,9 +63,12 @@ class ListingAutoPage(BasePage):
cost = ', ' + self._extract(tr, 'lcprice') cost = ', ' + self._extract(tr, 'lcprice')
price = Price(id) price = Price(id)
price.product = product
price.cost = Decimal(re.findall(r'\d+',cost.replace(' ',''))[0]) price.cost = Decimal(re.findall(r'\d+',cost.replace(' ',''))[0])
price.currency = u'' price.currency = u''
price.message = unicode(title) price.message = unicode(title)
price.shop = Shop(price.id)
price.shop.set_empty_fields(NotAvailable)
price.set_empty_fields(NotAvailable) price.set_empty_fields(NotAvailable)
yield price yield price