public PesquisaViewModel() { // _pesquisaCPFCNPJ = Global.Investidor; pesquisaBusiness = new PesquisaBusiness(); PesquisaCPFCNPJ = new PesquisaCPFCNPJModel(); PesquisarClickedCommand = new Command(() => { var mensagem = "Consulta Realizada com Sucesso"; try { ArpenspModel arpenspModel = pesquisaBusiness.Arpensp(PesquisaCPFCNPJ.CPFCNPJ); CagedModel cagedModel = pesquisaBusiness.Caged(PesquisaCPFCNPJ.CPFCNPJ); JucespModel jucespModel = pesquisaBusiness.Jucesp(PesquisaCPFCNPJ.CPFCNPJ); CensecModel censecModel = pesquisaBusiness.Censec(PesquisaCPFCNPJ.CPFCNPJ); SielModel sielModel = pesquisaBusiness.Siel(PesquisaCPFCNPJ.CPFCNPJ); SivecModel sivecModel = pesquisaBusiness.Sivec(PesquisaCPFCNPJ.CPFCNPJ); DetranModel detranModel = pesquisaBusiness.Detran(PesquisaCPFCNPJ.CPFCNPJ); } catch (Exception ex) { mensagem = "Não foi possível consultar os dados. Verifique sua conexão! \n Detalhe: " + ex.Message; } DependencyService.Get <IMessage>().ShortAlert(mensagem); MessagingCenter.Send <PesquisaViewModel>(this, "PesquisaSucesso"); }); }
public void Insert(JucespModel jucespModel) { using (context) { context.Jucesp.Add(jucespModel); context.SaveChanges(); } }
public JucespModel Jucesp(int cpfcnpj) { var jucesp = new Service.PesquisaService().Jucesp(cpfcnpj); JucespModel jucespModel = JsonConvert.DeserializeObject <JucespModel>(jucesp); //variavel global Global.Jucesp = jucespModel; return(jucespModel); }
public JucespModel getJucesp(string cnpj) { string uri = "http://10.0.2.2:8080/jucesp/cnpj?cnpj=" + cnpj; JucespModel jucesp = new JucespModel(); System.Net.Http.HttpClient client = new HttpClient(); var resposta = client.GetAsync(uri).Result; if (resposta.IsSuccessStatusCode) { var resultado = resposta.Content.ReadAsStringAsync().Result; jucesp = JsonConvert.DeserializeObject <JucespModel>(resultado); return(jucesp); } else { throw new Exception("Dados não encontrados"); } }
//Jucesp public string Jucesp(PesquisaCPFCNPJ pesquisaCPFCNPJ) { var options = new ChromeOptions(); options.AddArguments("headless"); using (IWebDriver driver = new ChromeDriver("C:/inetpub/wwwroot/wwwroot", options)) //using (IWebDriver driver = new ChromeDriver(options)) { Actions builder = new Actions(driver); driver.Navigate().GoToUrl("http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/jucesp/index.html"); driver.FindElement(By.Id("ctl00_cphContent_frmBuscaSimples_txtPalavraChave")).SendKeys(pesquisaCPFCNPJ.Nome); driver.FindElement(By.XPath("//*[@id='ctl00_cphContent_frmBuscaSimples_pnlBuscaSimples']/table/tbody/tr/td[2]/input")).Click(); driver.FindElement(By.XPath("//*[@id='formBuscaAvancada']/table/tbody/tr[1]/td/div/div[2]/label/input")).SendKeys("Q8TJA"); driver.FindElement(By.ClassName("btcadastro")).Click(); var tables = driver.FindElement(By.XPath("//*[@id='ctl00_cphContent_gdvResultadoBusca_gdvContent']/tbody")); var rows = tables.FindElements(By.TagName("tr")); var count = -1; foreach (var row in rows) { count++; } driver.FindElement(By.XPath("//*[@id='ctl00_cphContent_gdvResultadoBusca_gdvContent']/tbody/tr/td")).Click(); var resultadoFinal = driver.FindElement(By.Id("dados")).Text; string[] strsplit = resultadoFinal.Replace("\r\n", ":").Split(':'); string data = strsplit[1].Replace("17", "").Trim(); string nome = strsplit[4].Trim(); string nMatriz = strsplit[7].Trim(); string tipoEmpresa = strsplit[12].Trim(); string dataConst = strsplit[14].Trim(); string inicioAtiv = strsplit[16].Trim(); string cnpj = strsplit[18].Trim(); string capital = strsplit[26].Trim(); string logradouro = strsplit[28].Trim(); string numero = strsplit[30].Trim(); string complemento = strsplit[34].Trim(); string bairro = strsplit[32].Trim(); string municipio = strsplit[36].Trim(); string cep = strsplit[38].Trim(); string uf = strsplit[40].Trim(); JucespModel objJu = new JucespModel(); objJu.Data = data; objJu.Nome = nome; objJu.NumMatriz = nMatriz; objJu.TipoEmpresa = tipoEmpresa; objJu.DataConst = dataConst; objJu.InicioAtiv = inicioAtiv; objJu.CNPJJucesp = long.Parse(cnpj.Replace(".", "").Replace("/", "").Replace("-", "")); objJu.Capital = capital; objJu.Logradouro = logradouro; objJu.Numero = numero; objJu.Complemento = complemento; objJu.Bairro = bairro; objJu.Municipio = municipio; objJu.Cep = cep; objJu.Uf = uf; jucespRepository.Insert(objJu); string objjsonData = JsonConvert.SerializeObject(objJu, new JsonSerializerSettings { Formatting = Formatting.Indented }); //System.IO.File.WriteAllText(@"C:\Users\nperes\Desktop\Projeto\Arquivos\Jucesp.txt", objjsonData); return(objjsonData); } }
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 void WebScrapingJucesp() { using (IWebDriver driver = new ChromeDriver()) { driver.Manage().Window.Maximize(); driver.Navigate().GoToUrl("http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/ "); driver.FindElement(By.Id("username")).SendKeys("fiap"); driver.FindElement(By.Id("password")).SendKeys("mpsp"); driver.FindElement(By.Id("password")).SendKeys(Keys.Enter); Actions builder = new Actions(driver); driver.Navigate().GoToUrl("http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/jucesp/index.html"); driver.FindElement(By.Id("ctl00_cphContent_frmBuscaSimples_txtPalavraChave")).SendKeys("google"); driver.FindElement(By.XPath("//*[@id='ctl00_cphContent_frmBuscaSimples_pnlBuscaSimples']/table/tbody/tr/td[2]/input")).Click(); driver.FindElement(By.XPath("//*[@id='formBuscaAvancada']/table/tbody/tr[1]/td/div/div[2]/label/input")).SendKeys("Q8TJA"); driver.FindElement(By.ClassName("btcadastro")).Click(); var tables = driver.FindElement(By.XPath("//*[@id='ctl00_cphContent_gdvResultadoBusca_gdvContent']/tbody")); var rows = tables.FindElements(By.TagName("tr")); var count = -1; foreach (var row in rows) { count++; } driver.FindElement(By.XPath("//*[@id='ctl00_cphContent_gdvResultadoBusca_gdvContent']/tbody/tr/td")).Click(); var dados = driver.FindElement(By.Id("dados")).Text; string[] entersplit = dados.Split('\n'); //string enter = entersplit[3]; //string[] strsplit = enter.Split(':'); string[] strsplit = dados.Split(':'); string data = strsplit[1]; string nome = entersplit[1]; string nMatriz = entersplit[4]; string tipoEmpresa = entersplit[9]; string dataConst = entersplit[11]; string inicioAtiv = entersplit[13]; string cnpj = entersplit[15]; JucespModel objJu = new JucespModel(); objJu.Data = data; objJu.Nome = nome; objJu.NumMatriz = nMatriz; objJu.TipoEmpresa = tipoEmpresa; objJu.DataConst = dataConst; objJu.InicioAtiv = inicioAtiv; objJu.CNPJ = cnpj; string objjsonData = JsonConvert.SerializeObject(objJu); Response.Write(objjsonData); System.IO.File.WriteAllText(@"C:\Users\nperes\Desktop\Projeto\Arquivos\Jucesp.txt", objjsonData); } }
public JsonResult WebScrapingJucesp() { using (IWebDriver driver = new ChromeDriver()) { /*driver.Manage().Window.Maximize(); * driver.Navigate().GoToUrl("http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/ "); * driver.FindElement(By.Id("username")).SendKeys("fiap"); * driver.FindElement(By.Id("password")).SendKeys("mpsp"); * driver.FindElement(By.Id("password")).SendKeys(Keys.Enter); */ Actions builder = new Actions(driver); driver.Navigate().GoToUrl("http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/jucesp/index.html"); driver.FindElement(By.Id("ctl00_cphContent_frmBuscaSimples_txtPalavraChave")).SendKeys("google"); driver.FindElement(By.XPath("//*[@id='ctl00_cphContent_frmBuscaSimples_pnlBuscaSimples']/table/tbody/tr/td[2]/input")).Click(); driver.FindElement(By.XPath("//*[@id='formBuscaAvancada']/table/tbody/tr[1]/td/div/div[2]/label/input")).SendKeys("Q8TJA"); driver.FindElement(By.ClassName("btcadastro")).Click(); var tables = driver.FindElement(By.XPath("//*[@id='ctl00_cphContent_gdvResultadoBusca_gdvContent']/tbody")); var rows = tables.FindElements(By.TagName("tr")); var count = -1; foreach (var row in rows) { count++; } driver.FindElement(By.XPath("//*[@id='ctl00_cphContent_gdvResultadoBusca_gdvContent']/tbody/tr/td")).Click(); var resultadoFinal = driver.FindElement(By.Id("dados")).Text; string[] strsplit = resultadoFinal.Replace("\r\n", ":").Split(':'); string data = strsplit[1].Replace("17", ""); string nome = strsplit[4]; string nMatriz = strsplit[7]; string tipoEmpresa = strsplit[12]; string dataConst = strsplit[14]; string inicioAtiv = strsplit[16]; string cnpj = strsplit[18]; string capital = strsplit[26]; string logradouro = strsplit[28]; string numero = strsplit[30]; string complemento = strsplit[34]; string bairro = strsplit[32]; string municipio = strsplit[36]; string cep = strsplit[38]; string uf = strsplit[40]; JucespModel objJu = new JucespModel(); objJu.Data = data; objJu.Nome = nome; objJu.NumMatriz = nMatriz; objJu.TipoEmpresa = tipoEmpresa; objJu.DataConst = dataConst; objJu.InicioAtiv = inicioAtiv; objJu.CNPJ = cnpj; objJu.Capital = capital; objJu.Logradouro = logradouro; objJu.Numero = numero; objJu.Complemento = complemento; objJu.Bairro = bairro; objJu.Municipio = municipio; objJu.Cep = cep; objJu.Uf = uf; string objjsonData = JsonConvert.SerializeObject(objJu); Response.Write(objjsonData); System.IO.File.WriteAllText(@"C:\Users\nperes\Desktop\Projeto\Arquivos\Jucesp.txt", objjsonData); return(Json(objjsonData, JsonRequestBehavior.AllowGet)); } }
public PessoaJuridicaViewModel() { PesquisarClickedCommand = new Command(() => { var pessoaJuridicaBusiness = new PessoaJuridicaBusiness(); //Instanciando business para acessar a service e pegar dados da api var service = pessoaJuridicaBusiness.getService(); //atribuiu o objeto service a uma variavel para fazer as chamadas das API dentros dos IF conforme resultados do Picker var relatorio = new RelatorioViewModel(); // instancia relatorio para envio das informações para a tela //validação CNPJ NULO if (String.IsNullOrEmpty(cnpj) == true) { DependencyService.Get <IMessage>().ShortAlert("Por favor digite seu CNPJ"); } else { //Validação Picker Nulo if (baseDados == null) { DependencyService.Get <IMessage>().ShortAlert("Por favor selecione ao menos uma base de dados para consulta"); } else { if (baseDados == "Todos") { JucespModel jucesp = new JucespModel(); jucesp = service.getJucesp(cnpj); relatorio.Resultado = jucesp.ToString(); CadespModel cadesp = new CadespModel(); cadesp = service.getCadesp(cnpj); relatorio.Resultado += cadesp.ToString(); GlobalViewModel.Relatorio = relatorio;// manda os dados para a global, fazendo a RelatorioViewModel enxergar string sourceImage1 = service.getArisp(cnpj); relatorio.NomeImage = "------ARISP----"; relatorio.Image = sourceImage1; string sourceImage2 = service.getInfocrim(cnpj); relatorio.NomeImage2 = "------INFOCRIM----"; relatorio.Image2 = sourceImage2; GlobalViewModel.Relatorio = relatorio; } if (baseDados == "Jucesp") { JucespModel jucesp = new JucespModel(); jucesp = service.getJucesp(cnpj); relatorio.Resultado = jucesp.ToString(); GlobalViewModel.Relatorio = relatorio; } if (baseDados == "Cadesp") { CadespModel cadesp = new CadespModel(); cadesp = service.getCadesp(cnpj); relatorio.Resultado = cadesp.ToString(); GlobalViewModel.Relatorio = relatorio; } if (baseDados == "Arisp") { string sourceImage1 = service.getArisp(cnpj); relatorio.NomeImage = "------ARISP----"; relatorio.Image = sourceImage1; GlobalViewModel.Relatorio = relatorio; } if (baseDados == "Infocrim") { string sourceImage2 = service.getInfocrim(cnpj); relatorio.NomeImage = "------INFOCRIM----"; relatorio.Image = sourceImage2; GlobalViewModel.Relatorio = relatorio; } MessagingCenter.Send <PessoaJuridicaViewModel>(this, "RelatorioPageAbrir"); } } }); }
public ActionResult RelatorioSimplificado(PesquisaCPFCNPJ pesquisaCPFCNPJ) { string arpensp = ""; string cadesp = ""; string caged = ""; string censec = ""; string detran = ""; string juscesp = ""; string siel = ""; string sivec = ""; if (pesquisaCPFCNPJ.Arpensp == "on") { arpensp = webScraping.Arpensp(pesquisaCPFCNPJ); } if (pesquisaCPFCNPJ.Cadesp == "on") { cadesp = webScraping.Cadesp(pesquisaCPFCNPJ); } if (pesquisaCPFCNPJ.Caged == "on") { caged = webScraping.Caged(pesquisaCPFCNPJ); } if (pesquisaCPFCNPJ.Censec == "on") { censec = webScraping.Censec(pesquisaCPFCNPJ); } if (pesquisaCPFCNPJ.Jucesp == "on") { juscesp = webScraping.Jucesp(pesquisaCPFCNPJ); } if (pesquisaCPFCNPJ.Detran == "on") { detran = webScraping.Detran(pesquisaCPFCNPJ); } if (pesquisaCPFCNPJ.Siel == "on") { siel = webScraping.Siel(pesquisaCPFCNPJ); } if (pesquisaCPFCNPJ.Sivec == "on") { sivec = webScraping.Sivec(pesquisaCPFCNPJ); } ArpenspModel arpenspModel = relatorioSimplificadoRepository.SimplesArpensp(arpensp); CadespModel cadespModel = relatorioSimplificadoRepository.SimplesCadesp(cadesp); JucespModel jucespModel = relatorioSimplificadoRepository.SimplesJucesp(juscesp); CagedModel cagedModel = relatorioSimplificadoRepository.SimplesCaged(caged); DetranModel detranModel = relatorioSimplificadoRepository.SimplesDetran(detran); CensecModel censecModel = relatorioSimplificadoRepository.SimplesCensec(censec); SielModel sielModel = relatorioSimplificadoRepository.SimplesSiel(siel); SivecModel sivecModel = relatorioSimplificadoRepository.SimplesSivec(sivec); consultaAnteriorRepository.Insert(pesquisaCPFCNPJ); return(View(new PesquisaCPFCNPJ() { ArpenspModel = arpenspModel, CadespModel = cadespModel, JucespModel = jucespModel, CagedModel = cagedModel, DetranModel = detranModel, CensecModel = censecModel, SielModel = sielModel, SivecModel = sivecModel })); }
public JucespModel SimplesJucesp(string jucesp) { JucespModel jucespModel = JsonConvert.DeserializeObject <JucespModel>(jucesp); return(jucespModel); }