From 61718199d6c5e77aac4cb08d671f8ec6d3c4ba7b Mon Sep 17 00:00:00 2001 From: Florent Fourcot Date: Thu, 4 Jul 2013 21:35:25 +0200 Subject: [PATCH] Use yield instead to return a list --- modules/adecco/pages.py | 5 +---- modules/apec/pages.py | 4 +--- modules/lolix/pages.py | 4 +--- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/modules/adecco/pages.py b/modules/adecco/pages.py index 9ab35b33..940dd9fb 100644 --- a/modules/adecco/pages.py +++ b/modules/adecco/pages.py @@ -32,8 +32,6 @@ class SearchPage(BasePage): locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8') re_id = re.compile('http://www.adecco.fr/trouver-un-emploi/Pages/Details-de-l-Offre/(.*?)/(.*?).aspx\?IOF=(.*?)$', re.DOTALL) - adverts = [] - divs = self.document.getroot().xpath("//div[@class='resultContain right']") + self.document.getroot().xpath("//div[@class='resultContain left']") for div in divs: @@ -49,8 +47,7 @@ class SearchPage(BasePage): advert.publication_date = datetime.strptime(date, "%d %B %Y").date() advert.title = u'%s' % self.parser.select(div, "div/h3/a", 1, method='xpath').text_content() advert.place = u'%s' % self.parser.select(div, "div/h3/span[@class='offreLocalisation']", 1, method='xpath').text - adverts.append(advert) - return adverts + yield advert class AdvertPage(BasePage): diff --git a/modules/apec/pages.py b/modules/apec/pages.py index bccf7144..fdc58dbf 100644 --- a/modules/apec/pages.py +++ b/modules/apec/pages.py @@ -29,7 +29,6 @@ __all__ = ['SearchPage', 'AdvertPage'] class SearchPage(BasePage): def iter_job_adverts(self): - adverts = [] re_id_title = re.compile('/offres-emploi-cadres/\d*_\d*_\d*_(.*?)________(.*?).html(.*?)', re.DOTALL) divs = self.document.getroot().xpath("//div[@class='boxContent offre']") + self.document.getroot().xpath("//div[@class='boxContent offre even']") for div in divs: @@ -42,8 +41,7 @@ class SearchPage(BasePage): advert.place = u'%s' % l[-1].strip() date = self.parser.select(div, 'div/div/div', 1, method='xpath') advert.publication_date = dateutil.parser.parse(date.text_content().strip()[8:]).date() - adverts.append(advert) - return adverts + yield advert class AdvertPage(BasePage): diff --git a/modules/lolix/pages.py b/modules/lolix/pages.py index 24ea0e62..d319ba2d 100644 --- a/modules/lolix/pages.py +++ b/modules/lolix/pages.py @@ -70,13 +70,11 @@ class AdvertPage(BasePage): class SearchPage(BasePage): def iter_job_adverts(self): - adverts = [] rows = self.document.getroot().xpath('//td[@class="Contenu"]/table/tr') for row in rows: cols = self.is_row_advert(row) if cols is not None: - adverts.append(self.create_job_advert(cols)) - return adverts + yield self.create_job_advert(cols) def is_row_advert(self, row): cols = self.parser.select(row, 'td')