コード例 #1
0
    async def parse_page(self, session: aiohttp.ClientSession,
                         page_num: int) -> List[Data]:
        """ парсит отдельную страницу вытаскивая id и ссылку на закупку """

        param = self.params.copy()
        param['pageNumber'] = page_num
        orders = []

        data = await self._get_request(session, self.search_link, params=param)
        doc = document_fromstring(data)
        for link in doc.xpath(
                '//div[@class="registry-entry__header-mid__number"]/a'):
            order_id = self._tender_id_handler(
                self._normalizer(link.xpath('./text()')[0]))
            order_link = self.main_link + link.xpath('./@href')[0]
            tender = Data()
            tender.id = order_id
            tender.tender_link = order_link
            orders.append(tender)
        return orders
コード例 #2
0
ファイル: parser_zak.py プロジェクト: Qwerty10291/zakupki_web
    def db_handler(self, id, data):
        session = self.session_maker()
        db_data = Data()
        db_data.id = id
        db_data.tender_price = self._tender_price_handler(data['tender_price'])
        db_data.type = data['type']
        db_data.tender_date = self._tender_date_handler(data['tender_date'])
        db_data.tender_object = data['tender_object']
        db_data.customer = data['customer']
        db_data.tender_adress = data['tender_adress']
        db_data.tender_delivery = data['tender_delivery']
        db_data.tender_terms = data['tender_term']
        db_data.document_links = '\n'.join(data['document_links'])
        db_data.tender_link = data['link']

        winner = Winners()
        winner.data_id = id
        winner.name = data['tender_winner'][0]
        winner.position = data['tender_winner'][1]
        winner.price = data['tender_winner'][2]
        db_data.winner.append(winner)

        for i in data['tender_object_info'][1:]:
            if len(i) == 6:
                data = Objects()
                data.position = i[0]
                data.name = i[1]
                data.unit = i[2]
                data.quantity = i[3]
                data.unit_price = i[4]
                data.price = i[5]
                db_data.objects.append(data)
        
        session.add(db_data)
        session.commit()
        db_data.winner = [winner]
        session.close()
        return db_data