示例#1
0
        private static void GetLicitacoes(List <string> licitLinks)
        {
            foreach (var link in licitLinks)
            {
                try
                {
                    if (web != null)
                    {
                        web.Quit();
                    }

                    var driver = ChromeDriverService.CreateDefaultService();
                    driver.HideCommandPromptWindow = true;
                    var op = new ChromeOptions();
                    op.AddUserProfilePreference("download.default_directory", PathEditais);
                    web = new ChromeDriver(driver, new ChromeOptions(), TimeSpan.FromSeconds(300));
                    web.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(300);
                    wait = new WebDriverWait(web, TimeSpan.FromSeconds(300));

                    web.Navigate().GoToUrl(link);

                    CheckReCaptcha(web.PageSource);

                    var situacao  = web.FindElement(By.XPath("//*[@id=\"report_38717872527149671_catch\"]/dl/dd[4]")).Text;
                    var andamento = web.FindElement(By.XPath("//*[@id=\"L38976648273068799\"]/div/span[2]"));

                    if (!situacao.Contains("Encerrada") || !andamento.Text.Contains("Ativo"))
                    {
                        Licitacao licitacao = CreateLicitacao(link, situacao);

                        try
                        {
                            if (LicitacaoController.IsValid(licitacao, out mensagemErro) && !LicitacaoController.ExistsTCERS(licitacao.IdLicitacaoFonte, Constants.TCERS_ID_FONTE) /*!AlreadyInserted.Contains(licitacao.IdLicitacaoFonte)*/)
                            {
                                repo.Insert(licitacao);
                                NumLicitacoes++;
                                RService.Log("(GetLicitacoes) " + Name + ": Licitação nº" + licitacao.Num + " salva com sucesso at {0}", LogPath);

                                //GetArquivos(licitacao);
                            }
                            else if (!string.IsNullOrEmpty(mensagemErro))
                            {
                                RService.Log("Exception (GetLicitacoes - Insert) " + Name + ": " + mensagemErro + " at {0}", LogPath);
                            }
                            else
                            {
                                RService.Log("Exception (GetLicitacoes - Insert) " + Name + ": Licitação já capturada anteriormente at {0}", LogPath);
                            }
                        }
                        catch (Exception e)
                        {
                            RService.Log("Exception (GetLicitacoes - Insert) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", LogPath);
                        }
                    }
                }
                catch (Exception e)
                {
                    if (web.FindElement(By.Id("g-recaptcha-response")) != null)
                    {
                        RService.Log("Exception (GetLicitacoes) " + Name + ": Encontrado recaptcha! at {0}", LogPath);
                    }

                    RService.Log("Exception (GetLicitacoes) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", LogPath);
                }
            }
        }