def get_pages(self, stop):
    try:
        for page in range(self.start, stop):
            logging.info(('Crawl page: %s' % page))
            page_text = get_page(('http://bus.gov.ru/public/agency/choose.html?d-442831-p=' + str(page)))
            tree = html.fromstring(page_text)
            org_list = tree.xpath('//table[@id="resultTable"]/tbody/tr[*]')
            x = 1
            for org in org_list:
                name = tree.xpath((('//table[@id="resultTable"]/tbody/tr[' + str(x)) + ']/td[2]/text()'))[0].strip('\n  ')
                inn = tree.xpath((('//table[@id="resultTable"]/tbody/tr[' + str(x)) + ']/td[3]/text()'))[0]
                address = tree.xpath((('//table[@id="resultTable"]/tbody/tr[' + str(x)) + ']/td[4]/text()'))[0].strip('\n  ')
                item = {'name': name, 'inn': inn, 'address': address}
                x += 1
                self.processed(item=item, page=page)
            f = open('page.txt', 'w')
            f.write(str(page))
            f.close()
        else:
            raise logging.error(('Stop Crawl last page: %' % page))
    except Exception as e:
        logging.error(e.message)
def get_pages(self, stop):
    try:
        for page in range(self.start, stop):
            logging.info(('Crawl page: %s' % page))
            page_text = get_page(('http://bus.gov.ru/public/agency/choose.html?d-442831-p=' + str(page)))
            tree = html.fromstring(page_text)
            org_list = tree.xpath('//table[@id="resultTable"]/tbody/tr[*]')
            x = 1
            for org in org_list:
                name = tree.xpath((('//table[@id="resultTable"]/tbody/tr[' + str(x)) + ']/td[2]/text()'))[0].strip('\n  ')
                inn = tree.xpath((('//table[@id="resultTable"]/tbody/tr[' + str(x)) + ']/td[3]/text()'))[0]
                address = tree.xpath((('//table[@id="resultTable"]/tbody/tr[' + str(x)) + ']/td[4]/text()'))[0].strip('\n  ')
                item = {'name': name, 'inn': inn, 'address': address}
                x += 1
                self.processed(item=item, page=page)
            f = open('page.txt', 'w')
            f.write(str(page))
            f.close()
        else:
            raise logging.error(('Stop Crawl last page: %' % page))
    except Exception as e:
        logging.error(e.message)