pages.py 3.41 KB
Newer Older
1 2
# -*- coding: utf-8 -*-

Vicnet's avatar
Vicnet committed
3
# Copyright(C) 2014 Vicnet
4
#
5
# This file is part of a weboob module.
6
#
7
# This weboob module is free software: you can redistribute it and/or modify
8 9 10 11
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
12
# This weboob module is distributed in the hope that it will be useful,
13 14 15 16 17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
18
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
19 20


21 22 23 24 25 26 27 28 29 30 31 32 33
from weboob.browser.elements import ItemElement, ListElement, method
from weboob.browser.pages import HTMLPage, pagination
from weboob.browser.filters.standard import CleanText, Regexp, CleanDecimal, Format, Env, BrowserURL
from weboob.browser.filters.javascript import JSVar
from weboob.browser.filters.html import Link
from weboob.capabilities.pricecomparison import Price, Shop
from .product import LaCentraleProduct


class ListingAutoPage(HTMLPage):
    @pagination
    @method
    class iter_prices(ListElement):
34
        item_xpath = '//div[@class="adContainer "]'
35 36 37 38 39 40
        next_page = Link('//section[@class="pagination"]/ul/li[@class="last"]/a')

        class item(ItemElement):
            klass = Price

            obj_id = CleanText('./p/a/@data-annid')
41 42
            obj_cost = CleanDecimal('./a/div/div/div/div[@class="fieldPrice"]')
            obj_currency = Regexp(CleanText('./a/div/div/div/div[@class="fieldPrice"]'),
43
                                  '.*([%s%s%s])' % (u'€', u'$', u'£'), default=u'€')
44 45 46 47
            obj_message = Format('%s / %s / %s',
                                 CleanText('./a/div/div/h3'),
                                 CleanText('./a/div/div/div/div[@class="fieldYear"]'),
                                 CleanText('./a/div/div/div/div[@class="fieldMileage"]'))
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
            obj_url = Format('http://www.lacentrale.fr%s',
                             CleanText('./a/@href'))

            obj_product = LaCentraleProduct()

            def obj_shop(self):
                shop = Shop(CleanText('./p/a/@data-annid')(self))
                return shop


class AdvertPage(HTMLPage):

    @method
    class get_price(ItemElement):
        klass = Price

        obj_id = Env('_id')

        obj_cost = CleanDecimal('//div[@class="mainInfos"]/div/p[@class="gpfzj"]')
        obj_currency = Regexp(CleanText('//div[@class="mainInfos"]/div/p[@class="gpfzj"]'),
                              '.*([%s%s%s])' % (u'€', u'$', u'£'), default=u'€')
        obj_message = Format('%s %s',
                             CleanText('//div[@class="mainInfos"]/div/div/h1'),
                             CleanText('//div[@class="mainInfos"]/div/div/p'))
        obj_url = BrowserURL('advert_page', _id=Env('_id'))

        def obj_shop(self):
            shop = Shop(Env('_id')(self))
            shop.name = Regexp(CleanText('(//div[@xtcz="contacter_le_vendeur"]/div/ul/li)[1]'),
                               'Nom : (.*)')(self)
            shop.location = JSVar(CleanText('//script'), var='tooltip')(self)
            shop.info = CleanText('//div[@xtcz="contacter_le_vendeur"]/div/ul/li[has-class("printPhone")]')(self)
            return shop

        obj_product = LaCentraleProduct()