public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { driver.Navigate().GoToUrl(String.Format("https://www.google.com/search?hl=pt-BR&q={0}&oq={0}", _busca)); // page 1 - Capturar dados result = null; driver.Close(); Console.WriteLine("ExampleCrawler OK"); return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.WriteLine("Fail loading browser caught: {0}", e.Message); SetErrorMessage(typeof(ExampleCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e.Message); SetErrorMessage(typeof(ExampleCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }
public WebDriverTestsBase() { var chromeOptions = new ChromeOptions(); chromeOptions.AddArgument("--headless"); ChromeDriver = new ChromeDriver(ChromeDriverPath, chromeOptions); WebDriverService.SetupProperty(x => x.Driver, ChromeDriver); WebDriverService.Setup(x => x.GetDriver()).Returns(ChromeDriver); }
public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { driver.Navigate().GoToUrl(@"https://www.escavador.com"); var resultado = new EscavadorModel(); if (_tipo.Equals("Physical")) { driver.FindElement(By.CssSelector(".c-search-box_input")).SendKeys(_busca); driver.FindElement(By.CssSelector(".c-search-box_buttonLabel")).Click(); } if (_tipo.Equals("Legal")) { driver.FindElement(By.CssSelector(".c-search-box_input")).Click(); driver.FindElement(By.CssSelector("li.c-search-box_filtersOption:nth-child(2) > button:nth-child(1)")).Click(); driver.FindElement(By.CssSelector(".c-search-box_input")).SendKeys(_busca); driver.FindElement(By.CssSelector(".c-search-box_buttonLabel")).Click(); } Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot(); var nameEscavador = $"{_pathTemp}/escavador-{ss}.png"; ss.SaveAsFile(nameEscavador); #region Objeto com os dados capturados resultado = new EscavadorModel { Imagem1 = nameEscavador }; #endregion driver.Close(); Console.WriteLine("EscavadorCrawler OK"); result = resultado; return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.WriteLine("Fail loading browser caught: {0}", e.Message); SetErrorMessage(typeof(EscavadorCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e.Message); SetErrorMessage(typeof(EscavadorCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }
public virtual void SetupTest() { Log.WriteLine(LogLevel.None, "_____________________________"); Log.Debug("Setting up..."); //Log.Info(Util.getCurrentMachineInfo()); LogCurrentMachineInfo(LogLevel.Info); Initialize(); // Create Webdriver Config config = new WebDriverConfig(browser, browserVersion, nodeURL, platform); // Create WebDriver based on WebDriver Config driver = WebDriverService.Create(config); // Initialize HRBC driver HRBC.Initialize(driver); // Log test start time startTime = DateTime.Now; }
public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { driver.Navigate().GoToUrl(@"http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/cadesp/login.html"); // page 1 driver.FindElement(By.Id("ctl00_conteudoPaginaPlaceHolder_loginControl_UserName")).SendKeys("1"); driver.FindElement(By.Id("ctl00_conteudoPaginaPlaceHolder_loginControl_Password")).SendKeys("1"); driver.FindElement(By.CssSelector("ctl00_conteudoPaginaPlaceHolder_loginControl_loginButton")).Click(); // page 2 Actions actionPage2 = new Actions(driver); var menuDropDown = driver.FindElement(By.CssSelector("#ctl00_menuPlaceHolder_menuControl1_LoginView1_menuSuperiorn1 > table")); actionPage2.MoveToElement(menuDropDown).Build().Perform(); driver.FindElement(By.CssSelector("#ctl00_menuPlaceHolder_menuControl1_LoginView1_menuSuperiorn1 > table > tbody > tr > td > a")).Click(); // page 3 driver.FindElement(By.Id("ctl00_conteudoPaginaPlaceHolder_tcConsultaCompleta_TabPanel1_txtIdentificacao")).SendKeys(_cnpj); driver.FindElement(By.Id("ctl00_conteudoPaginaPlaceHolder_tcConsultaCompleta_TabPanel1_btnConsultarEstabelecimento")).Click(); // page 4 - Capturar dados var downloadFolderPath = $@"{AppDomain.CurrentDomain.BaseDirectory}temp\cadesp\"; if (!Directory.Exists(downloadFolderPath)) { Directory.CreateDirectory(downloadFolderPath); } var data = DateTime.Now.ToString("yyyyMMddhhmm", System.Globalization.CultureInfo.InvariantCulture); var arquivo = $@"{downloadFolderPath}{_cnpj}_{data}.png"; try { Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot(); screenshot.SaveAsFile(arquivo, ScreenshotImageFormat.Png); } catch (Exception e) { Console.WriteLine("[CADESP] Ocorreu um erro ao capturara a tela! \nMensagem de erro: " + e); result = null; return(CrawlerStatus.Skipped); } var cadespResult = new CadespModel { Imagem = arquivo }; result = cadespResult; driver.Close(); Console.WriteLine("CadespCrawler OK"); return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.WriteLine("Fail loading browser caught: {0}", e.Message); SetErrorMessage(typeof(CadespCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e.Message); SetErrorMessage(typeof(CadespCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }
public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { driver.Navigate().GoToUrl(@"http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/caged/login.html"); //page 1 - Login driver.FindElement(By.Id("username")).SendKeys(_usuario); driver.FindElement(By.Id("password")).SendKeys(_senha); driver.FindElement(By.Id("btn-submit")).Click(); result = null; //page 2 - Autorizado/Responsável IWebElement menuDropDown; if (_cnpj != null) { Actions actionPage2 = new Actions(driver); menuDropDown = driver.FindElement(By.Id("j_idt12:lk_menu_consultas")); actionPage2.MoveToElement(menuDropDown).Build().Perform(); driver.FindElement(By.Id("j_idt12:idMenuLinkAutorizado")).Click(); //page 3 - Consultar responsável //TODO: BUG NO WEBSITE ao trocar o valor do campo, ele automaticamente passa para a página seguinte /* * IWebElement pesquisarDropDown = driver.FindElement(By.Id("formPesquisarAutorizado:slctTipoPesquisaAutorizado")); * var dropdown = new SelectElement(pesquisarDropDown); * dropdown.SelectByIndex(0); */ driver.FindElement(By.Id("formPesquisarAutorizado:txtChavePesquisaAutorizado014")).Click(); driver.FindElement(By.Id("formPesquisarAutorizado:txtChavePesquisaAutorizado014")) .SendKeys(Keys.Home + _cnpj); driver.FindElement(By.Id("formPesquisarAutorizado:bt027_8")).Click(); //page 4 - Capturar dados responsável var razaoSocial = driver.FindElement(By.Id("txtrazaosocial020_4")).Text; var logradouro = driver.FindElement(By.Id("txt3_logradouro020")).Text; var bairro = driver.FindElement(By.Id("txt4_bairro020")).Text; var municipio = driver.FindElement(By.Id("txt6_municipio020")).Text; var estado = driver.FindElement(By.Id("txt7_uf020")).Text; var cep = driver.FindElement(By.Id("txt8_cep020")).Text; var nomeContato = driver.FindElement(By.Id("txt_nome_contato")).Text; var cpfContato = driver.FindElement(By.Id("txt_contato_cpf")).Text; var telefoneContato = driver.FindElement(By.Id("txt21_ddd020")).Text + driver.FindElement(By.Id("txt9_telefone020")).Text; var ramalContato = driver.FindElement(By.Id("txt10_ramal020")).Text; var emailContato = driver.FindElement(By.Id("txt11_email")).Text; //--- passar para a próxima página Actions actionPage4 = new Actions(driver); menuDropDown = driver.FindElement(By.Id("j_idt12:lk_menu_consultas")); actionPage4.MoveToElement(menuDropDown).Build().Perform(); driver.FindElement(By.Id("j_idt12:idMenuLinkEmpresaCaged")).Click(); // page 5 - Consultar Empresa driver.FindElement(By.Id("formPesquisarEmpresaCAGED:txtcnpjRaiz")).Click(); driver.FindElement(By.Id("formPesquisarEmpresaCAGED:txtcnpjRaiz")) .SendKeys(Keys.Home + _cnpj.Substring(0, 8)); driver.FindElement(By.Id("formPesquisarEmpresaCAGED:btConsultar")).Click(); //page 6 - Capturar dados empresa var cnae = driver.FindElement(By.Id("formResumoEmpresaCaged:txtCodigoAtividadeEconomica")).Text; var atividadeEconomica = driver .FindElement(By.Id("formResumoEmpresaCaged:txtDescricaoAtividadeEconomica")).Text; var noFilias = Int32.Parse(driver.FindElement(By.Id("formResumoEmpresaCaged:txtNumFiliais")).Text); var totalVinculos = Int32.Parse(driver.FindElement(By.Id("formResumoEmpresaCaged:txtTotalVinculos")).Text); #region Salvar dados de pessoa jurídica no objeto var pessoaJuridica = new CagedPJModel { Cnpj = _cnpj, RazaoSocial = razaoSocial, Logradouro = logradouro, Bairro = bairro, Municipio = municipio, Estado = estado, Cep = cep, NomeContato = nomeContato, CpfContato = cpfContato, TelefoneContato = telefoneContato, RamalContato = ramalContato, EmailContato = emailContato, Cnae = cnae, AtividadeEconomica = atividadeEconomica, NoFilias = noFilias, TotalVinculos = totalVinculos }; #endregion result = pessoaJuridica; } else if (_cpf != null) { Actions actionPage6 = new Actions(driver); menuDropDown = driver.FindElement(By.Id("j_idt12:lk_menu_consultas")); actionPage6.MoveToElement(menuDropDown).Build().Perform(); driver.FindElement(By.Id("j_idt12:idMenuLinkTrabalhador")).Click(); //page 7 - Consultar trabalhador IWebElement pesquisarPorDropDown = driver.FindElement(By.Id("formPesquisarTrabalhador:slctTipoPesquisaTrabalhador")); new SelectElement(pesquisarPorDropDown).SelectByIndex(0); driver.FindElement(By.Id("formPesquisarTrabalhador:txtChavePesquisa")).Click(); driver.FindElement(By.Id("formPesquisarTrabalhador:txtChavePesquisa")) .SendKeys(Keys.Home + _cpf); driver.FindElement(By.Id("formPesquisarTrabalhador:submitPesqTrab")).Click(); //Page 8 - Capturar dados trabalhador var nomeTrabalhador = driver.FindElement(By.Id("txt2_Nome027")).Text; var pisBaseTrabalhador = driver.FindElement(By.Id("txt1_Pis028")).Text; var ctpsTrabalhador = driver.FindElement(By.Id("txt5_Ctps027")).Text; var faixaPisTrabalhador = driver.FindElement(By.Id("txt4_SitPis027")).Text; var nacionalidadeTrabalhador = driver.FindElement(By.Id("txt8_Nac027")).Text; var grauInstrucaoTrabalhador = driver.FindElement(By.Id("txt12_Instr027")).Text; var deficienteTrabalhador = driver.FindElement(By.Id("txt13_Def027")).Text; var dataNascimentoTrabalhador = driver.FindElement(By.Id("txt4_datanasc027")).Text; var sexoTrabalhador = driver.FindElement(By.Id("txt6_Sexo027")).Text; var corTrabalhador = driver.FindElement(By.Id("txt10_Raca027")).Text; var cepTrabalhador = driver.FindElement(By.Id("txtEstabCep91")).Text; var tempoTrabalhoCaged = driver.FindElement(By.Id("txt26_Caged027")).Text + " meses"; var tempoTrabalhoRais = driver.FindElement(By.Id("txt27_Rais027")).Text + " meses"; driver.Navigate().GoToUrl(driver.FindElement(By.CssSelector(".link > a:nth-child(1)")).GetAttribute("href")); Console.WriteLine(); //Page 9 - Salvar PDF ReadOnlyCollection <string> windowHandles = driver.WindowHandles; driver.SwitchTo().Window(windowHandles.Last()); IWait <IWebDriver> wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30.00)); wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState") .Equals("complete")); var downloadFolderPath = $@"{AppDomain.CurrentDomain.BaseDirectory}temp\caged\"; if (!Directory.Exists(downloadFolderPath)) { Directory.CreateDirectory(downloadFolderPath); } var nomeArquivo = nomeTrabalhador.Replace(" ", string.Empty); var data = DateTime.Now.ToString("yyyyMMddhhmm", System.Globalization.CultureInfo.InvariantCulture); var arquivo = $@"{downloadFolderPath}{nomeArquivo}_{data}.pdf"; try { using (var client = new WebClient()) { client.DownloadFile(new Uri(driver.Url), arquivo); Console.WriteLine($@"PDF baixado com sucesso em {arquivo}"); } } catch (Exception e) { Console.WriteLine("[CAGED] Ocorreu um erro ao tentar baixar o PDF! \nMensagem de erro: " + e); result = null; return(CrawlerStatus.Skipped); } #region Salvar dados de pessoa física no objeto var pessoaFisica = new CagedPFModel { Cpf = _cpf, NomeTrabalhador = nomeTrabalhador, PisBaseTrabalhador = pisBaseTrabalhador, CtpsTrabalhador = ctpsTrabalhador, FaixaPisTrabalhador = faixaPisTrabalhador, NacionalidadeTrabalhador = nacionalidadeTrabalhador, GrauInstrucaoTrabalhador = grauInstrucaoTrabalhador, DeficienteTrabalhador = deficienteTrabalhador, DataNascimentoTrabalhador = dataNascimentoTrabalhador, SexoTrabalhador = sexoTrabalhador, CorTrabalhador = corTrabalhador, CepTrabalhador = cepTrabalhador, TempoTrabalhoCaged = tempoTrabalhoCaged, TempoTrabalhoRais = tempoTrabalhoRais, Arquivo = arquivo }; #endregion result = pessoaFisica; } driver.Close(); Console.WriteLine("CagedCrawler OK"); return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.Write("{0} Faill loading browser caught.", e.Message); SetErrorMessage(typeof(CagedCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.Write("{0} Exception caught.", e.Message); SetErrorMessage(typeof(CagedCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }
public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { driver.Navigate().GoToUrl(@"http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/siel/login.html"); // page 1 - Login // Inserir usuário e senha -> Clicar em Enviar driver.FindElement(By.CssSelector("div.mioloInterna.apps > form > table > tbody > tr:nth-child(1) > td:nth-child(2) > input[type=text]")).SendKeys(_usuario); driver.FindElement(By.CssSelector("div.mioloInterna.apps > form > table > tbody > tr:nth-child(2) > td:nth-child(2) > input[type=password]")).SendKeys(_senha); driver.FindElement(By.CssSelector("div.mioloInterna.apps > form > table > tbody > tr:nth-child(3) > td:nth-child(2) > input[type=submit]")).Click(); // page 2 - Pesquisa // Inserir Nome e Número do processo -> Clicar em Enviar if (!string.IsNullOrEmpty(_nomeCompleto) && !string.IsNullOrEmpty(_nomeDaMae) && !string.IsNullOrEmpty(_dataNascimento)) { driver.FindElement(By.CssSelector("form.formulario > fieldset:nth-child(1) > table > tbody > tr:nth-child(1) > td:nth-child(2) > input[type=text]")).SendKeys(_nomeCompleto); driver.FindElement(By.CssSelector("form.formulario > fieldset:nth-child(1) > table > tbody > tr:nth-child(2) > td:nth-child(2) > input[type=text]")).SendKeys(_nomeDaMae); driver.FindElement(By.CssSelector("form.formulario > fieldset:nth-child(1) > table > tbody > tr:nth-child(3) > td:nth-child(2) > input[type=text]")).SendKeys(_dataNascimento); } if (!string.IsNullOrEmpty(_tituloEleitor)) { driver.FindElement(By.CssSelector("form.formulario > fieldset:nth-child(1) > table > tbody > tr:nth-child(4) > td:nth-child(2) > input[type=text]")).SendKeys(_tituloEleitor); } driver.FindElement(By.Id("num_processo")).SendKeys(_numeroProcesso); driver.FindElement(By.CssSelector("form.formulario > table > tbody > tr > td:nth-child(2) > input")).Click(); // page 3 - Capturar dados var dados = driver.FindElements(By.CssSelector(".lista tbody > tr > td:nth-child(2)")); #region Objeto com os dados capturados var resultado = new SielModel { Nome = dados[0].Text, Titulo = dados[1].Text, DataNascimento = dados[2].Text, Zona = dados[3].Text, Endereco = dados[4].Text, Municipio = dados[5].Text, UF = dados[6].Text, DataDomicilio = dados[7].Text, NomePai = dados[8].Text, NomeMae = dados[9].Text, Naturalidade = dados[10].Text, CodValidacao = dados[11].Text }; #endregion result = resultado; driver.Close(); Console.WriteLine("SielCrawler OK"); return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.WriteLine("Fail loading browser caught: {0}", e.Message); SetErrorMessage(typeof(SielCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e.Message); SetErrorMessage(typeof(SielCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }
public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { driver.Navigate().GoToUrl(@"http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/arpensp/login.html"); // page 1 driver.FindElement(By.CssSelector("#main > div.container > div:nth-child(2) > div:nth-child(2) > div > a")).Click(); // page 2 //driver.FindElement(By.Id("arrumaMenu")).Click(); driver.FindElement(By.CssSelector("#wrapper > ul > li.item3 > a")).Click(); driver.FindElement(By.CssSelector("#wrapper > ul > li.item3 > ul > li:nth-child(1) > a")).Click(); // page 3 driver.FindElement(By.CssSelector("#principal > div > form > table > tbody > tr:nth-child(2) > td:nth-child(2) > input[name='numero_processo']")).SendKeys(_numeroProcesso); var campoVara = new SelectElement(driver.FindElement(By.Id("vara_juiz_id"))); campoVara.SelectByValue("297"); driver.FindElement(By.Id("btn_pesquisar")).Click(); // page 4 - Capturar dados #region Objeto com os dados capturados var resultado = new ArpenspModel { CartorioRegistro = driver.FindElement(By.CssSelector( "#principal > div > form > table:nth-child(3) > tbody > tr:nth-child(1) > td:nth-child(2)")) .Text.Trim(), NumeroCNS = driver .FindElement(By.CssSelector( "#principal > div > form > table:nth-child(3) > tbody > tr:nth-child(2) > td:nth-child(2)")) .Text.Trim(), UF = driver.FindElement(By.CssSelector( "#principal > div > form > table:nth-child(3) > tbody > tr:nth-child(3) > td:nth-child(2)")) .Text.Trim(), NomeConjugeA1 = driver .FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(2) > td:nth-child(2)")) .Text.Trim(), NovoNomeConjugeA2 = driver.FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(3) > td:nth-child(2)")) .Text.Trim(), NomeConjugeB1 = driver .FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(4) > td:nth-child(2)")) .Text.Trim(), NovoNomeConjugeB2 = driver.FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(5) > td:nth-child(2)")) .Text.Trim(), DataCasamento = driver .FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(6) > td:nth-child(2)")) .Text.Trim(), Matricula = driver .FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(8) > td:nth-child(2)")) .Text.Trim(), DataEntrada = driver .FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(9) > td:nth-child(2)")) .Text.Trim(), DataRegistro = driver .FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(10) > td:nth-child(2)")) .Text.Trim(), Acervo = driver .FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(11) > td:nth-child(2)")) .Text.Trim(), NumeroLivro = driver .FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(12) > td:nth-child(2)")) .Text.Trim(), NumeroFolha = driver .FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(13) > td:nth-child(2)")) .Text.Trim(), NumeroRegistro = driver.FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(14) > td:nth-child(2)")) .Text.Trim(), TipoLivro = driver .FindElement(By.CssSelector( "#principal > div > form > table:nth-child(15) > tbody > tr:nth-child(15) > td:nth-child(2)")) .Text.Trim() }; #endregion result = resultado; driver.Close(); Console.WriteLine("ArpenspCrawler OK"); return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.WriteLine("Fail loading browser caught: {0}", e.Message); SetErrorMessage(typeof(ArpenspCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e.Message); SetErrorMessage(typeof(ArpenspCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }
public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { driver.Navigate().GoToUrl(@"http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/arisp/login.html"); // page 1 driver.FindElement(By.Id("btnCallLogin")).Click(); driver.FindElement(By.Id("btnAutenticar")).Click(); // page 2 Actions actionPage2 = new Actions(driver); var menuDropDown = driver.FindElement(By.Id("liInstituicoes")); actionPage2.MoveToElement(menuDropDown).Build().Perform(); driver.FindElement(By.CssSelector("#liInstituicoes > div > ul > li:nth-child(3) > a")).Click(); // page 3 driver.FindElement(By.Id("Prosseguir")).Click(); // page 4 driver.FindElement(By.CssSelector("div.selectorAll div.checkbox input")).Click(); driver.FindElement(By.Id("chkHabilitar")).Click(); driver.FindElement(By.Id("Prosseguir")).Click(); // page 5 if (_type.Equals(KindPerson.LegalPerson)) { var campoFilter = new SelectElement(driver.FindElement(By.Id("filterTipo"))); campoFilter.SelectByValue("2"); } IWebElement campoBusca = driver.FindElement(By.Id("filterDocumento")); campoBusca.SendKeys(_identification); driver.FindElement(By.Id("btnPesquisar")).Click(); // page 6 var buttonSelectAll = driver.FindElement(By.Id("btnSelecionarTudo")); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", buttonSelectAll); buttonSelectAll.Click(); driver.FindElement(By.Id("btnProsseguir")).Click(); // page 7 var pathTemp = $@"{AppDomain.CurrentDomain.BaseDirectory}/temp/arisp"; var rnd = new Random(); if (!Directory.Exists(pathTemp)) { Directory.CreateDirectory(pathTemp); } var contador = 0; var processos = driver.FindElements(By.CssSelector("#panelMatriculas > tr > td:nth-child(4) a.list.listDetails")); List <ProcessoModel> resultados = new List <ProcessoModel>(); foreach (IWebElement processo in processos) { contador++; var cidade = driver.FindElement(By.CssSelector($"#panelMatriculas > tr:nth-child({contador}) > td:nth-child(1)")).Text.Trim(); var cartorio = driver.FindElement(By.CssSelector($"#panelMatriculas > tr:nth-child({contador}) > td:nth-child(2)")).Text.Trim(); var matricula = driver.FindElement(By.CssSelector($"#panelMatriculas > tr:nth-child({contador}) > td:nth-child(3)")).Text.Trim(); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", processo); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].removeAttribute('href');", processo); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", processo); // page 8 - Capturar dados var tabs = driver.WindowHandles; // indo para a janela aberta driver.SwitchTo().Window(tabs[tabs.Count - 1]); var nameFile = $"{pathTemp}/matricula-{rnd.Next(1000, 10001)}.png"; Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot(); screenshot.SaveAsFile(nameFile, ScreenshotImageFormat.Png); #region Objeto com os dados capturados resultados.Add(new ProcessoModel { Cidade = cidade, Cartorio = cartorio, Matricula = matricula, Arquivo = nameFile }); #endregion // fechando a janela aberta driver.Close(); // voltando para a janela anterior driver.SwitchTo().Window(tabs[tabs.Count - 2]); } var arisp = new ArispModel(); arisp.Processos = resultados; result = arisp; driver.Close(); Console.WriteLine("ArispCrawler OK"); return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.WriteLine("Fail loading browser caught: {0}", e.Message); SetErrorMessage(typeof(ArispCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e.Message); SetErrorMessage(typeof(ArispCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }
public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { driver.Navigate().GoToUrl(@"http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/censec/login.html"); // page 1 driver.FindElement(By.Id("LoginTextBox")).SendKeys(_usuario); driver.FindElement(By.Id("LoginTextBox")).SendKeys(_usuario); driver.FindElement(By.Id("SenhaTextBox")).SendKeys(_senha); driver.FindElement(By.Id("EntrarButton")).Click(); // page 2 Actions builder = new Actions(driver); //desfazer o menu ja aberto var saifora = driver.FindElement(By.Id("menuadministrativo")); builder.MoveToElement(saifora).Build().Perform(); var menuDropDown = driver.FindElement(By.Id("menucentrais")); builder.MoveToElement(menuDropDown).Build().Perform(); var menuDropDown2 = driver.FindElement(By.Id("ctl00_CESDILi")); builder.MoveToElement(menuDropDown2).Build().Perform(); driver.FindElement(By.Id("ctl00_CESDIConsultaAtoHyperLink")).Click(); // page 3 driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_DocumentoTextBox")).SendKeys(_cpf); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_BuscarButton")).Click(); // page 4 driver.FindElement(By.CssSelector("tr.linha1Tabela:nth-child(2) > td:nth-child(1) > input:nth-child(1)")).Click(); driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_VisualizarButton")).Click(); // page 5 //recuperar dados var nome = ""; var cpfCnpj = ""; var qualidade = ""; var telefone = ""; var tipoTel = ""; var ramal = ""; var contato = ""; var status = ""; //dados dos campos var resultadoCarga = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_CodigoTextBox")).GetAttribute("value"); var resultadoMes = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_MesReferenciaDropDownList")).Text; var resultadoAno = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_AnoReferenciaDropDownList")).Text; var resultadoAto = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_TipoAtoDropDownList")).Text; var resultadoDiaAto = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_DiaAtoTextBox")).GetAttribute("value"); var resultadoMesAto = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_MesAtoTextBox")).GetAttribute("value"); var resultadoAnoAto = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_AnoAtoTextBox")).GetAttribute("value"); var resultadoLivro = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_LivroTextBox")).GetAttribute("value"); var resultadoComplementoLivro = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_LivroComplementoTextBox")).GetAttribute("value"); var resultadoFolha = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_FolhaTextBox")).GetAttribute("value"); var resultadoComplementoFolha = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_FolhaComplementoTextBox")).GetAttribute("value"); //dados da tabela var resultados = driver.FindElements(By.CssSelector("#ctl00_ContentPlaceHolder1_PartesUpdatePanel > table > tbody > tr")); for (int i = 1; i <= resultados.Count; i++) { nome += driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_PartesUpdatePanel > table > tbody > tr:nth-child(" + i + ") > td:nth-child(2)")).Text + "\n"; cpfCnpj += driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_PartesUpdatePanel > table > tbody > tr:nth-child(" + i + ") > td:nth-child(3)")).Text + "\n"; qualidade += driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_PartesUpdatePanel > table > tbody > tr:nth-child(" + i + ") > td:nth-child(4)")).Text + "\n"; } var resultadoUf = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_DadosCartorio_CartorioUFTextBox")).GetAttribute("value"); var resultadoMunicipio = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_DadosCartorio_CartorioMunicipioTextBox")).GetAttribute("value"); var resultadoCartorio = driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_DadosCartorio_CartorioNomeTextBox")).GetAttribute("value"); var resultados2 = driver.FindElements(By.CssSelector("#ctl00_ContentPlaceHolder1_DadosCartorio_DivTelefonesCartorioListView > div > table > tbody > tr")); for (int i = 1; i <= resultados2.Count; i++) { telefone += driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_DadosCartorio_DivTelefonesCartorioListView > div > table > tbody > tr:nth-child(" + i + ") > td:nth-child(1)")).Text + "\n"; tipoTel += driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_DadosCartorio_DivTelefonesCartorioListView > div > table > tbody > tr:nth-child(" + i + ") > td:nth-child(2)")).Text + "\n"; ramal += driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_DadosCartorio_DivTelefonesCartorioListView > div > table > tbody > tr:nth-child(" + i + ") > td:nth-child(3)")).Text + "\n"; contato += driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_DadosCartorio_DivTelefonesCartorioListView > div > table > tbody > tr:nth-child(" + i + ") > td:nth-child(4)")).Text + "\n"; status += driver.FindElement(By.CssSelector("#ctl00_ContentPlaceHolder1_DadosCartorio_DivTelefonesCartorioListView > div > table > tbody > tr:nth-child(" + i + ") > td:nth-child(5)")).Text + "\n"; } #region Objeto com os dados capturados var resultado = new CensecModel { Carga = resultadoCarga, Data = resultadoMes + "/" + resultadoAno, Ato = resultadoAto, DataAto = resultadoDiaAto + "/" + resultadoMesAto + "/" + resultadoAnoAto, Livro = resultadoLivro + "-" + resultadoComplementoLivro, Folha = resultadoFolha + "-" + resultadoComplementoFolha, Nomes = nome, CpfsCnpjs = cpfCnpj, Qualidads = qualidade, Uf = resultadoUf, Municipio = resultadoMunicipio, Cartorio = resultadoCartorio, Telefones = telefone, TipoTel = tipoTel, Ramal = ramal, Contato = contato, Status = status, }; #endregion result = resultado; driver.Close(); Console.WriteLine("CensecCrawler OK"); return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.WriteLine("Fail loading browser caught: {0}", e.Message); SetErrorMessage(typeof(CensecCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e.Message); SetErrorMessage(typeof(CensecCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }
public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { driver.Navigate().GoToUrl("http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/sivec/login.html"); // page 1 driver.FindElement(By.Id("nomeusuario")).SendKeys(_usuario); driver.FindElement(By.Id("senhausuario")).SendKeys(_senha); driver.FindElement(By.Id("Acessar")).Click(); // page 2 driver.FindElement(By.CssSelector("#navbar-collapse-1 > ul > li:nth-child(4) > a")).Click(); driver.FindElement(By.Id("1")).Click(); if (!string.IsNullOrEmpty(_rg)) { driver.FindElement(By.CssSelector("li.open:nth-child(2) > ul:nth-child(2) > li:nth-child(1) > a:nth-child(1)")).Click(); } else if (!string.IsNullOrEmpty(_nomeCompleto)) { driver.FindElement(By.CssSelector("li.open:nth-child(2) > ul:nth-child(2) > li:nth-child(1) > a:nth-child(2)")).Click(); } else if (!string.IsNullOrEmpty(_matriculaSap)) { driver.FindElement(By.CssSelector("li.open:nth-child(2) > ul:nth-child(2) > li:nth-child(1) > a:nth-child(3)")).Click(); } // page 3 if (!string.IsNullOrEmpty(_rg)) { driver.FindElement(By.Id("idValorPesq")).SendKeys(_rg); driver.FindElement(By.Id("procurar")).Click(); } else if (!string.IsNullOrEmpty(_nomeCompleto)) { driver.FindElement(By.Id("idNomePesq")).SendKeys(_nomeCompleto); driver.FindElement(By.Id("procura")).Click(); } else if (!string.IsNullOrEmpty(_matriculaSap)) { driver.FindElement(By.Id("idValorPesq")).SendKeys(_matriculaSap); driver.FindElement(By.Id("procurar")).Click(); } // page 4 var personFind = driver.FindElement(By.CssSelector("#tabelaPesquisa > tbody > tr:nth-child(1) > td.textotab1.text-center.sorting_1 > a")); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", personFind); personFind.Click(); // page 5 - Capturar dados const string caminhoTabela = "body > form:nth-child(13) > div > "; #region Objeto com os dados capturados var outrasInfo = new OutrosModel { Nome = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(10) > div.col-md-9")).Text.Trim(), RG = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(11) > div:nth-child(2)")).Text.Trim(), DataNascimento = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(12) > div.col-md-5")).Text.Trim(), Naturalidade = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(13) > div.col-md-7")).Text.Trim(), NomePai = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(14) > div.col-md-9")).Text.Trim(), NomeMae = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(15) > div.col-md-9")).Text.Trim() }; var resultado = new SivecModel { Nome = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-11 > table > tbody > tr:nth-child(1) > td:nth-child(2)")).Text.Trim(), Sexo = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-11 > table > tbody > tr:nth-child(1) > td:nth-child(5)")).Text.Trim(), DataNascimento = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-11 > table > tbody > tr:nth-child(2) > td:nth-child(2)")).Text.Trim(), RG = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-11 > table > tbody > tr:nth-child(2) > td:nth-child(5)")).Text.Trim(), NumControle = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-11 > table > tbody > tr:nth-child(3) > td:nth-child(2)")).Text.Trim(), TipoRG = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-11 > table > tbody > tr:nth-child(3) > td:nth-child(5)")).Text.Trim(), DataEmissaoRG = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(1) > td:nth-child(2)")).Text.Trim(), Alcunha = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(1) > td:nth-child(5)")).Text.Trim(), EstadoCivil = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(2) > td:nth-child(2)")).Text.Trim(), Naturalidade = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(2) > td:nth-child(5)")).Text.Trim(), Naturalizado = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(3) > td:nth-child(2)")).Text.Trim(), PostoIdentificacao = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(3) > td:nth-child(5)")).Text.Trim(), GrauInstrucao = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(4) > td:nth-child(2)")).Text.Trim(), FormulaFundamental = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(4) > td:nth-child(5)")).Text.Trim(), NomePai = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(5) > td:nth-child(2)")).Text.Trim(), CorOlhos = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(5) > td:nth-child(5)")).Text.Trim(), NomeMae = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(6) > td:nth-child(2)")).Text.Trim(), Cabelo = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(6) > td:nth-child(5)")).Text.Trim(), CorPele = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(7) > td:nth-child(2)")).Text.Trim(), Profissao = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(5) > div.col-md-12.top-buffer25 > table > tbody > tr:nth-child(7) > td:nth-child(5)")).Text.Trim(), EnderecoResidencial = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(7) > div.col-md-7")).Text.Trim(), EnderecoTrabalho = driver .FindElement(By.CssSelector($"{caminhoTabela}div:nth-child(8) > div.col-md-7")).Text.Trim(), Outros = outrasInfo }; #endregion result = resultado; driver.Close(); Console.WriteLine("SivecCrawler OK"); return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.WriteLine("Fail loading browser caught: {0}", e.Message); SetErrorMessage(typeof(SivecCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e.Message); SetErrorMessage(typeof(SivecCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }
public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { driver.Navigate().GoToUrl(@"http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/jucesp/index.html"); // page 1 driver.FindElement(By.Id("ctl00_cphContent_frmBuscaSimples_txtPalavraChave")).Click(); driver.FindElement(By.Id("ctl00_cphContent_frmBuscaSimples_txtPalavraChave")).SendKeys("Google"); driver.FindElement(By.XPath("/html/body/div[4]/form/div[3]/div[4]/div[1]/div/div[1]/table/tbody/tr/td[2]/input")).Click(); // page 2 driver.FindElement(By.XPath("/html/body/div[4]/div[3]/div[4]/div[2]/div/div/table/tbody/tr[1]/td/div/div[2]/label/input")).Click(); driver.FindElement(By.XPath("/html/body/div[4]/div[3]/div[4]/div[2]/div/div/table/tbody/tr[1]/td/div/div[2]/label/input")).SendKeys("Q8TJA"); driver.FindElement(By.XPath("/html/body/div[4]/div[3]/div[4]/div[2]/div/div/table/tbody/tr[2]/td/input")).Click(); // page 3 driver.FindElement(By.Id("ctl00_cphContent_gdvResultadoBusca_gdvContent_ctl02_lbtSelecionar")).Click(); // page 4 var tituloEmpresa = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblEmpresa")).Text.Trim(); var nireMatriz = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblNire")).Text.Trim(); var tipoEmpresa = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblDetalhes")).Text.Trim(); var dataConstituicao = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblConstituicao")).Text.Trim(); var inicioAtividade = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblAtividade")).Text.Trim(); var cNPJ = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblCnpj")).Text.Trim(); var inscricaoEstadual = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblInscricao")).Text.Trim(); var objeto = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblObjeto")).Text.Trim(); var capital = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblCapital")).Text.Trim(); var logradouro = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblLogradouro")).Text.Trim(); var numero = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblNumero")).Text.Trim(); var bairro = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblBairro")).Text.Trim(); var complemento = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblComplemento")).Text.Trim(); var municipio = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblMunicipio")).Text.Trim(); var cep = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblCep")).Text.Trim(); var uF = driver.FindElement(By.Id("ctl00_cphContent_frmPreVisualiza_lblUf")).Text.Trim(); // PDF driver.FindElement(By.XPath("/html/body/div[4]/form/div[3]/div[4]/div/div[1]/div[2]/table/tbody/tr[3]/td/div/input")).Click(); ReadOnlyCollection <string> windowHandles = driver.WindowHandles; driver.SwitchTo().Window(windowHandles.Last()); IWait <IWebDriver> wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30.00)); wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState") .Equals("complete")); var downloadFolderPath = $@"{AppDomain.CurrentDomain.BaseDirectory}temp\jucesp\"; if (!Directory.Exists(downloadFolderPath)) { Directory.CreateDirectory(downloadFolderPath); } var nomeArquivo = tituloEmpresa.Replace(" ", string.Empty); var data = DateTime.Now.ToString("yyyyMMddhhmm", System.Globalization.CultureInfo.InvariantCulture); var arquivo = $@"{downloadFolderPath}{nomeArquivo}_{data}.pdf"; try { using (var client = new WebClient()) { client.DownloadFile(new Uri(driver.Url), arquivo); Console.WriteLine($@"PDF baixado com sucesso em {arquivo}"); } } catch (Exception e) { Console.WriteLine("[JUCESP] Ocorreu um erro ao tentar baixar o PDF! \nMensagem de erro: " + e); result = null; return(CrawlerStatus.Skipped); } driver.Close(); var jucesp = new JucespModel { TituloEmpresa = tituloEmpresa, NireMatriz = nireMatriz, TipoEmpresa = tipoEmpresa, DataConstituicao = dataConstituicao, InicioAtividade = inicioAtividade, CNPJ = cNPJ, InscricaoEstadual = inscricaoEstadual, Objeto = objeto, Capital = capital, Logradouro = logradouro, Numero = numero, Bairro = bairro, Complemento = complemento, Municipio = municipio, Cep = cep, UF = uF }; result = jucesp; driver.Close(); Console.WriteLine("ArispCrawler OK"); return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.WriteLine("Fail loading browser caught: {0}", e.Message); SetErrorMessage(typeof(JucespCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e.Message); SetErrorMessage(typeof(JucespCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }
public CicekSepetiTest() { driverPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); webDriverService = new WebDriverService(); }
public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { var lastTab = driver.WindowHandles.Last(); var firstTab = driver.WindowHandles.First(); var data = DateTime.Now.ToString("yyyyMMddhhmm", System.Globalization.CultureInfo.InvariantCulture); driver.Navigate().GoToUrl(@"http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/detran/login.html"); // page 1 driver.FindElement(By.Id("form:j_id563205015_44efc1ab")).SendKeys(_usuario); driver.FindElement(By.Id("form:j_id563205015_44efc191")).SendKeys(_senha); driver.FindElement(By.Id("form:j_id563205015_44efc15b")).Click(); var resultado = new DetranModel(); if (_tipo.Equals("Physical")) { // page 2 Actions builder1 = new Actions(driver); var menuDropDown1 = driver.FindElement(By.Id("navigation_a_M_16")); builder1.MoveToElement(menuDropDown1).Build().Perform(); //Thread.Sleep(5000); driver.FindElement(By.Id("navigation_a_F_16")).Click(); // page 3 // TODO: INSERIR MAIS DADOS PESSOAIS DE BUSCA driver.FindElement(By.Id("form:cpf")).SendKeys(_cpf); driver.FindElement(By.Id("form:rg")).SendKeys(_rg); driver.FindElement(By.CssSelector("#form\\:j_id2049423534_c43228e_content > table:nth-child(3) > tbody > tr > td > a")).Click(); // page 4 - Capturar dados 1 // indo para a janela aberta lastTab = driver.WindowHandles.Last(); driver.SwitchTo().Window(lastTab); var nameFileLinhaVida = $"{_pathTemp}/linhadeVida-{data}.pdf"; client.DownloadFileAsync(new Uri(driver.Url), nameFileLinhaVida); // fechando a janela aberta driver.Close(); // page 3 // voltando para a janela anterior driver.SwitchTo().Window(firstTab); Actions builder2 = new Actions(driver); var menuDropDown2 = driver.FindElement(By.Id("navigation_a_M_16")); builder2.MoveToElement(menuDropDown2).Build().Perform(); driver.FindElement(By.CssSelector("#navigation_ul_M_16 > li:nth-child(2) > a:nth-child(1)")).Click(); // page 4 driver.FindElement(By.Id("form:cpf")).SendKeys(_cpf); driver.FindElement(By.CssSelector("a.ui-button > span:nth-child(1)")).Click(); // page 5 - Capturar dados 2 lastTab = driver.WindowHandles.Last(); driver.SwitchTo().Window(lastTab); var resultadoRenach = driver.FindElement(By.CssSelector("#form\\:pnCNH > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > span:nth-child(2)")).Text.Trim(); var resultadoCategoria = driver.FindElement(By.CssSelector("#form\\:pnCNH > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > span:nth-child(2)")).Text.Trim(); var resultadoEmissão = driver.FindElement(By.CssSelector("#form\\:pnCNH > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(3) > span:nth-child(2)")).Text.Trim(); var resultadoNascimento = driver.FindElement(By.CssSelector("#form\\:pnCNH > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(4) > span:nth-child(2)")).Text.Trim(); var resultadoNomeCondutor = driver.FindElement(By.CssSelector("#form\\:pnCNH > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > span:nth-child(1)")).Text.Trim(); var resultadoNomePai = driver.FindElement(By.CssSelector("#form\\:pnCNH > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > span:nth-child(1)")).Text.Trim(); var resultadoNomeMae = driver.FindElement(By.CssSelector("#form\\:pnCNH > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > span:nth-child(1)")).Text.Trim(); var resultadoRegistro = driver.FindElement(By.CssSelector("#form\\:pnCNH > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > span:nth-child(2)")).Text.Trim(); var resultadoTipografico = driver.FindElement(By.CssSelector("#form\\:pnCNH > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > span:nth-child(2)")).Text.Trim(); var resultadoRg = driver.FindElement(By.CssSelector("#form\\:pnCNH > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(3) > span:nth-child(2)")).Text.Trim(); var resultadoCpf = driver.FindElement(By.CssSelector("#form\\:pnCNH > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(4) > span:nth-child(2)")).Text.Trim(); try { var fotoSrc = driver.FindElement(By.Id("form:imgFoto")).GetAttribute("src"); var assinaturaSrc = driver.FindElement(By.Id("form:imgAssinatura")).GetAttribute("src"); //var rndPicture = new Random(); //var nextRndPicture = rndPicture.Next(1000, 10001); var nameFileFoto = $@"{_pathTemp}/foto_{data}.png"; client.DownloadFile(new Uri(fotoSrc), nameFileFoto); var nameFileAssinatura = $@"{_pathTemp}/assinatura_{data}.png"; client.DownloadFileAsync(new Uri(assinaturaSrc), nameFileAssinatura); #region Objeto com os dados capturados resultado = new DetranModel { Renach = resultadoRenach, Categoria = resultadoCategoria, Emissao = resultadoEmissão, Nascimento = resultadoNascimento, Nome = resultadoNomeCondutor, NomePai = resultadoNomePai, NomeMae = resultadoNomeMae, Registro = resultadoRegistro, Tipografo = resultadoTipografico, RG = resultadoRg, CPF = resultadoCpf, Arquivo1 = nameFileLinhaVida, Imagem1 = nameFileFoto, Imagem2 = nameFileAssinatura, }; #endregion } catch (Exception e) { Console.WriteLine("[DETRAN] Ocorreu um erro ao tentar baixar as Imagens! \nMensagem de erro: " + e); result = null; return(CrawlerStatus.Skipped); } // page 6 // voltando para a janela anterior driver.Close(); firstTab = driver.WindowHandles.First(); driver.SwitchTo().Window(firstTab); } Actions builder3 = new Actions(driver); var menuDropDown3 = driver.FindElement(By.Id("navigation_a_M_18")); builder3.MoveToElement(menuDropDown3).Build().Perform(); driver.FindElement(By.CssSelector("#navigation_a_F_18")).Click(); // page 7 if (_cpf != null) { driver.FindElement(By.Id("form:j_id2124610415_1b3be1e3")).SendKeys(_cpf); } if (_cnpj != null) { driver.FindElement(By.Id("form:j_id2124610415_1b3be1e3")).SendKeys(_cnpj); } driver.FindElement(By.CssSelector("a.ui-button > span:nth-child(1)")).Click(); // page 8 - Capturar dados 3 lastTab = driver.WindowHandles.Last(); driver.SwitchTo().Window(lastTab); var nameFileVeiculo = $@"{_pathTemp}/relatorioveiculo_{data}.pdf"; client.DownloadFileAsync(new Uri(driver.Url), nameFileVeiculo); driver.Close(); firstTab = driver.WindowHandles.First(); driver.SwitchTo().Window(firstTab); driver.Close(); if (_tipo.Equals("Physical")) { resultado.Arquivo2 = nameFileVeiculo; } else { #region Objeto com os dados capturados resultado = new DetranModel { Arquivo2 = nameFileVeiculo }; #endregion } Console.WriteLine("DetranCrawler OK"); result = resultado; return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.WriteLine("Fail loading browser caught: {0}", e.Message); SetErrorMessage(typeof(DetranCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e.Message); SetErrorMessage(typeof(DetranCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }
public override CrawlerStatus Execute(out object result) { try { using (var driver = WebDriverService.CreateWebDriver(WebBrowser.Firefox)) { IWait <IWebDriver> wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30.00)); driver.Navigate().GoToUrl(@"http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/login"); // page 1 driver.FindElement(By.Id("username")).SendKeys("fiap"); driver.FindElement(By.Id("password")).SendKeys("mpsp"); driver.FindElement(By.CssSelector(".btn")).Click(); driver.Navigate().GoToUrl(@"http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/infocrim/login.html"); //page 1 wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState") .Equals("complete")); driver.FindElement(By.CssSelector("#wrapper > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(3) > input:nth-child(1)")) .SendKeys(_usuario); driver.FindElement(By.CssSelector("#wrapper > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(3) > input:nth-child(1)")) .SendKeys(_senha); driver.FindElement(By.CssSelector("#wrapper > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(4) > a:nth-child(1)")) .Click(); //page 2 var agora = DateTime.Now.ToString("ddmmyyyy"); driver.FindElement(By.Id("dtIni")).SendKeys(agora); driver.FindElement(By.Id("dtFim")).SendKeys(agora); driver.FindElement(By.Id("enviar")).Click(); //page 3 var nome = driver.FindElement(By.CssSelector("body > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(3) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(5) > font:nth-child(2)")).Text; driver.FindElement(By.CssSelector("body > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(3) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > a:nth-child(2)")).Click(); nome = nome.Replace(" ", ""); //page 4 var downloadFolderPath = $@"{AppDomain.CurrentDomain.BaseDirectory}temp\infocrim\"; if (!Directory.Exists(downloadFolderPath)) { Directory.CreateDirectory(downloadFolderPath); } var datahora = DateTime.Now.ToString("yyyyMMddhhmm"); var arquivoBO = $"{downloadFolderPath}/BO_{nome}_{datahora}.png"; ITakesScreenshot screenshotDriver = driver as ITakesScreenshot; Screenshot screenshot = screenshotDriver.GetScreenshot(); screenshot.SaveAsFile(arquivoBO, ScreenshotImageFormat.Png); var resultados = new InfocrimModel { BO = arquivoBO }; result = resultados; Console.WriteLine("InfocrimCrawler OK"); return(CrawlerStatus.Success); } } catch (NotSupportedException e) { Console.WriteLine("Fail loading browser caught: {0}", e.Message); SetErrorMessage(typeof(InfocrimCrawler), e.Message); result = null; return(CrawlerStatus.Skipped); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e.Message); SetErrorMessage(typeof(InfocrimCrawler), e.Message); result = null; return(CrawlerStatus.Error); } }