def select_option(self, localization):
     """ Selecionando uma opção"""
     option = Chrome.find_elements_by_xpath(
         "//select[@id='region-selector']//option[text() = '{}']".format(
             localization))[0]
     asyncio.get_event_loop().run_until_complete(
         Chrome.select_option("region-selector", option.attrs['value']))
Example #2
0
    def search(self):
        titles = []

        # Inicializando a sessão e pegando as tabelas
        Chrome.get_url(self.url, self.after_load_url)
        frames = Chrome.driver.html.page.frames

        for index, frame in enumerate(frames):
            if frame.url == self.url or frame.url == 'about:blank':
                continue

            html = asyncio.get_event_loop().run_until_complete(frame.content())
            if 'Machine type' not in html:
                continue

            Log.debug(f'Frame {index} de {len(frames)}')
            Chrome.driver._html = HTML(session=frame, url=frame.url, html=html)
            Chrome.driver._html.page = frame
            """ Pegando o select de seleção de localização """
            localizations = self.get_localizations()
            """ Interagindo sobre as localizações """
            idx = 0
            for localization in localizations:
                idx += 1
                Log.debug('Mudando a localização para {}. {} de {}'.format(
                    localization, idx, len(localizations)))
                """ Selecionando a opção para processar as informações dela """
                self.select_option(localization)
                self.tables = Chrome.get_tables()

                for table in self.tables:
                    self.process_table(table, titles, localization)
Example #3
0
 def select_option(self, localization):
     """ Selecionando uma opção"""
     options = Chrome.find_elements_by_xpath(
         "//md-option//div[@class='md-text'][contains(text(),'{}')]/..".
         format(localization))
     for option in options:
         asyncio.get_event_loop().run_until_complete(
             Chrome.execute_script(
                 "() => document.getElementById('{}').click()".format(
                     option.attrs['id'])))
         sleep(2)
         asyncio.get_event_loop().run_until_complete(
             Chrome.execute_script(
                 "() => { "
                 "         var element = document.getElementsByClassName('md-select-backdrop')[0];"
                 "         if (element) element.click(); "
                 "} "))
    def get_localizations(self):
        options = []
        options_elements = Chrome.find_elements_by_xpath(
            "//select[@id='region-selector']//option")

        for option in options_elements:
            options.append(option.text)

        return options
Example #5
0
    def get_localizations(self):
        options = []
        options_page = Chrome.find_elements_by_xpath(
            "//md-option//div[@class='md-text']")
        for option in options_page:
            text = option.text
            if text not in options and len(text) > 0:
                options.append(text)

        return options
Example #6
0
    def search(self):
        titles = []

        # Inicializando a sessão e pegando as tabelas
        Chrome.get_url(self.url, self.after_load_url)
        """ Pegando o select de seleção de localização """
        localizations = self.get_localizations()
        """ Interagindo sobre as localizações """
        idx = 0
        for localization in localizations:
            idx += 1
            Log.debug('Mudando a localização para {}. {} de {}'.format(
                localization, idx, len(localizations)))
            """ Selecionando a opção para processar as informações dela """
            self.select_option(localization)
            self.tables = Chrome.get_tables()

            for table in self.tables:
                self.process_table(table, titles, localization)
Example #7
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("cloud", help='Digite a cloud desejada', type=str)
    Chrome.initialize_driver()

    args = parser.parse_args()
    if args.cloud == 'all' or args.cloud == 'aws':
        prices_drive = AwsDriver()
        prices_drive.get()
        del prices_drive
        # Forçando o Garbage Collector do python rodar para liberar memoria
        gc.collect()

    if args.cloud == 'all' or args.cloud == 'azure':
        prices_drive = AzureDriver()
        prices_drive.get()
        del prices_drive
        # Forçando o Garbage Collector do python rodar para liberar memoria
        gc.collect()

    if args.cloud == 'all' or args.cloud == 'google':
        prices_drive = GoogleDriver()
        prices_drive.get()
        del prices_drive
        # Forçando o Garbage Collector do python rodar para liberar memoria
        gc.collect()

    if args.cloud == 'all' or args.cloud == 'alibaba':
        prices_drive = AlibabaDriver()
        prices_drive.get()
        del prices_drive
        # Forçando o Garbage Collector do python rodar para liberar memoria
        gc.collect()

    if args.cloud == 'all' or args.cloud == 'oracle':
        prices_drive = OracleDriver()
        prices_drive.get()
        del prices_drive
        # Forçando o Garbage Collector do python rodar para liberar memoria
        gc.collect()

    Chrome.close_selenium()
Example #8
0
 def get_localizations(self):
     asyncio.get_event_loop().run_until_complete(Chrome.click_using_text_and_tag('Mid East And India', 'div'))
     asyncio.get_event_loop().run_until_complete(Chrome.click_using_text_and_tag('Europe And America', 'div'))
     selects = asyncio.get_event_loop().run_until_complete(Chrome.driver.html.page.evaluate('REGION_DATA'))
     return [_['label'] for _ in selects.values()]
Example #9
0
 def select_option(self, localization):
     asyncio.get_event_loop().run_until_complete(Chrome.click_using_text_and_tag(localization, 'button'))
     sleep(2)
 def after_load_url(self):
     sleep(5)
     asyncio.get_event_loop().run_until_complete(
         Chrome.execute_script('() => document.documentElement.innerHTML'))
Example #11
0
    def process_table(self, table, titles, localization):
        thead = Chrome.find_element_by_tag_name(table, "thead")
        all_tbody = Chrome.find_elements_by_tag_name(table, "tbody")
        """ Buscando as colunas. Tem sites que utilizam o td no lugar do th """
        ths = Chrome.find_elements_by_tag_name(thead, "th")
        if len(ths) <= 0:
            ths = Chrome.find_elements_by_tag_name(thead, "td")

        for th in ths:
            if th.text not in titles:
                titles.append(th.text)

        for tbody in all_tbody:
            trs_body = Chrome.find_elements_by_tag_name(tbody, "tr")
            for tr in trs_body:
                tds = Chrome.find_elements_by_tag_name(tr, "td")
                key = None

                if len(tds) <= 2:
                    continue

                for index, td in enumerate(tds):
                    if index >= len(titles):
                        continue

                    if 'hidden' in td.attrs:
                        continue

                    text_th = titles[index]

                    # pulando itens que não possuem texto. Ex: botões na tabela
                    if td.text == "" or td.text is None:
                        continue

                    if key is None:
                        key = td.text

                    if key not in self.columns:
                        self.columns[key] = {}
                    """ Se for um valor agrupar em princing, se não só adicionar como uma coluna """
                    if str(td.text).startswith('$'):
                        if 'pricing' not in self.columns[key]:
                            self.columns[key]['pricing'] = {}

                        if localization not in self.columns[key]['pricing']:
                            self.columns[key]['pricing'][localization] = {}

                        self.columns[key]['pricing'][localization][
                            text_th] = td.text
                    else:
                        if text_th not in self.columns[key]:
                            self.columns[key][text_th] = {}

                        value = td.text

                        # Removendo parte dos valores que contém / para maquinas da azure
                        # Algumas máquina vem com um valor de cpu diferente, como por exemplo 2 / 4,
                        # nesses casos vamos considerar apenas o 2
                        if self.collection_name == 'azure':
                            items = str(td.text).split('/')
                            value = items[0]
                            if len(items) > 1 and str(td.text) != 'N/A':
                                Log.debug('Removendo parte do valor de ' +
                                          td.text + ' valor agora sera: ' +
                                          value)

                        self.columns[key][text_th] = value