//Método específico para o Diário Oficial de Pocinhos private static string getContentDOPocinhos(FontePesquisa fp) { string[] element = fp.Regex.Split(';'); string format = string.Empty; web.Navigate().GoToUrl(fp.Link); Thread.Sleep(1000); var data = DateTime.Now; int mes = data.Month; int ano = data.Year; web.FindElement(By.XPath(element[0])).Click(); web.FindElement(By.XPath("//*[@id='table23']/tbody/tr/td/form/select[1]/option[2]")).Click(); web.FindElement(By.XPath(element[1])).Click(); web.FindElement(By.XPath(string.Format("//*[@id='table23']/tbody/tr/td/form/select[2]/option[{0}]", mes + 1))).Click(); web.FindElement(By.XPath(element[2])).Click(); web.Navigate().GoToUrl(string.Format("view-source:http://pocinhos.pb.gov.br/portaldatransparencia/data{0}.htm", mes < 10 ? ano + "0" + mes : ano + mes.ToString())); Thread.Sleep(1000); return(web.PageSource); }
private static HtmlDocument SitesComCodigoFrame(FontePesquisa f) { List <string> lstViewSourcePage = new List <string>(); HtmlDocument html = new HtmlDocument(); if (f.Nome.Equals("Diário Oficial de São Félix do Coribe")) { lstViewSourcePage.Add("view-source:http://procedebahia.com.br/ba/saofelixdocoribe/io/"); } if (f.Nome.Equals("Diário Oficial de Rio Brilhante - MS")) { lstViewSourcePage.Add("view-source:http://www.diariooficial.inf.br/arquivos.asp"); } if (lstViewSourcePage.Count != 0) { ChromeDriver web = new ChromeDriver(); web.Navigate().GoToUrl(f.Link); Thread.Sleep(2000); web.Navigate().GoToUrl(lstViewSourcePage[0]); Thread.Sleep(5000); string codigoFonte = web.PageSource; html.DocumentNode.InnerHtml = codigoFonte; web.Quit(); } return(html); }
//Método específico para o Diário Oficial de Guarujá private static string getContentDOGuaruja(FontePesquisa fp) { web.Navigate().GoToUrl(fp.Link + string.Format("index.php/{0}{1}", meses[DateTime.Now.Month - 1], DateTime.Now.Year)); Thread.Sleep(2000); return(web.FindElement(By.XPath(fp.Regex)).GetAttribute("innerHTML")); }
//Método específico para o Diário Oficial do Governo do Maranhão private static string GetContentDOMaranhao(FontePesquisa fp) { string content = string.Empty; web.Navigate().GoToUrl(fp.Link); web.FindElement(By.Name("formPesq:calendarInic_input")).SendKeys(DateTime.Today.AddDays(-1).ToString("dd/MM/yyyy")); web.FindElement(By.Name("formPesq:calendarFim_input")).SendKeys(DateTime.Today.ToString("dd/MM/yyyy")); new SelectElement(web.FindElement(By.Name("formPesq:comboCaderno"))).SelectByText("Executivo"); web.FindElement(By.Name("formPesq:j_idt98")).Click(); Thread.Sleep(1000); if (!web.PageSource.Contains("Não há resultados para essa consulta.")) { content = content + "\n\n" + web.FindElement(By.XPath(fp.Regex)).GetAttribute("innerHTML").ToString(); } new SelectElement(web.FindElement(By.Name("formPesq:comboCaderno"))).SelectByText("Judiciário"); web.FindElement(By.Name("formPesq:j_idt98")).Click(); Thread.Sleep(1000); if (!web.PageSource.Contains("Não há resultados para essa consulta.")) { content = content + "\n\n" + web.FindElement(By.XPath(fp.Regex)).GetAttribute("innerHTML").ToString(); } new SelectElement(web.FindElement(By.Name("formPesq:comboCaderno"))).SelectByText("Terceiros"); web.FindElement(By.Name("formPesq:j_idt98")).Click(); Thread.Sleep(1000); if (!web.PageSource.Contains("Não há resultados para essa consulta.")) { content = content + "\n\n" + web.FindElement(By.XPath(fp.Regex)).GetAttribute("innerHTML").ToString(); } new SelectElement(web.FindElement(By.Name("formPesq:comboCaderno"))).SelectByText("Suplemento Executivo"); web.FindElement(By.Name("formPesq:j_idt98")).Click(); Thread.Sleep(1000); if (!web.PageSource.Contains("Não há resultados para essa consulta.")) { content = content + "\n\n" + web.FindElement(By.XPath(fp.Regex)).GetAttribute("innerHTML").ToString(); } new SelectElement(web.FindElement(By.Name("formPesq:comboCaderno"))).SelectByText("Suplemento Judiciário"); web.FindElement(By.Name("formPesq:j_idt98")).Click(); Thread.Sleep(3000); if (!web.PageSource.Contains("Não há resultados para essa consulta.")) { content = content + "\n\n" + web.FindElement(By.XPath(fp.Regex)).GetAttribute("innerHTML").ToString(); } new SelectElement(web.FindElement(By.Name("formPesq:comboCaderno"))).SelectByText("Suplemento de Terceiros"); web.FindElement(By.Name("formPesq:j_idt98")).Click(); Thread.Sleep(3000); if (!web.PageSource.Contains("Não há resultados para essa consulta.")) { content = content + "\n\n" + web.FindElement(By.XPath(fp.Regex)).GetAttribute("innerHTML").ToString(); } return(content); }
//Método específico para o Diário Oficial de Candeal private static string GetContentDOCandeal(FontePesquisa fp) { int cont = 0; IWebElement mesSelecionado = null; IWebElement diaSelecionado = null; List <IWebElement> addMes = new List <IWebElement>(); List <IWebElement> addDia = new List <IWebElement>(); web.Navigate().GoToUrl(fp.Link); Thread.Sleep(500); web.FindElement(By.XPath(fp.Regex)).Click(); Thread.Sleep(1000); var blocoMeses = web.FindElement(By.XPath("//*[@id='ui-id-2']")); var lstMeses = blocoMeses.FindElements(By.TagName("h5")); foreach (var mes in lstMeses) { if (meses.Contains(mes.Text)) { addMes.Add(mes); } } foreach (var mes in addMes) { cont++; if (cont == addMes.Count) { mes.Click(); mesSelecionado = mes; cont = 0; } } Thread.Sleep(1000); string getAttributeMes = mesSelecionado.GetAttribute("aria-controls"); var getDias = blocoMeses.FindElement(By.XPath("//div[@id='" + getAttributeMes + "']")); var lstDias = getDias.FindElements(By.TagName("h5")); foreach (var diaLic in lstDias) { cont++; if (cont == lstDias.Count) { diaLic.Click(); diaSelecionado = diaLic; } } Thread.Sleep(1000); string getAttributeDia = diaSelecionado.GetAttribute("aria-controls"); var getEdicao = getDias.FindElement(By.XPath("//div[@id='" + getAttributeDia + "']")); return(getEdicao.GetAttribute("innerText")); }
//Método específico para o Diário Oficial de Lavras private static string GetContentDOLavras(FontePesquisa fp) { string content = string.Empty; web.Navigate().GoToUrl(fp.Link); web.ExecuteScript("document.getElementsByClassName('doclink')[0].setAttribute('target', '_self')"); web.FindElement(By.XPath(fp.Regex)).Click(); Thread.Sleep(30000); var d = web.FindElements(By.ClassName("diarioOficial-titulo")); content = d[0].GetAttribute("innerHTML").ToString(); return(content); }
//Método específico para a Imprensa Oficial do Rio de Janeiro private static string GetContentIORJ(FontePesquisa fp) { string content = string.Empty; string[] element = fp.Regex.Split(';'); web.Navigate().GoToUrl(fp.Link); web.FindElement(By.Name("uname")).SendKeys("fabiored"); web.FindElement(By.Name("pass")).SendKeys("bingo66"); web.FindElement(By.XPath(element[0])).Click(); Thread.Sleep(5000); web.Navigate().GoToUrl("http://www.ioerj.com.br/portal/modules/conteudoonline/do_ultima_edicao.php"); content = web.FindElement(By.XPath(element[1])).GetAttribute("innerHTML").ToString(); return(content); }
//Método específico para o Diário Oficial de Canoas private static string GetContentDOCanoas(FontePesquisa fp) { string content = string.Empty; string[] element = fp.Regex.Split(';'); web.Navigate().GoToUrl(fp.Link); web.FindElement(By.XPath(element[0])).Click(); web.FindElement(By.Id("j_idt31:dataPublicacao1_input")).SendKeys(DateTime.Today.ToString("dd/MM/yyyy")); web.FindElement(By.Id("j_idt31:dataPublicacao1_input")).SendKeys(Keys.Escape); web.FindElement(By.Id("j_idt31:dataPublicacao1_input")).SendKeys(Keys.Enter); web.FindElement(By.XPath(element[1])).Click(); content = web.FindElement(By.XPath(element[2])).GetAttribute("innerHTML").ToString(); return(content); }
//Método específico para o Diário Oficial de Ariranha do Avaí e Lidianópolis private static string getContentDOAriranhaAvai(FontePesquisa fp) { if (fp.Nome == "Diário Oficial de Lidianópolis - PR") { web.Navigate().GoToUrl(fp.Link + string.Format("publicMes15.php?public={0}&ano={1}", meses[DateTime.Now.Month - 1], DateTime.Now.Year)); Thread.Sleep(1000); return(web.FindElement(By.XPath("//*[@id='conteudo_direito_meio']/table/tbody")).GetAttribute("innerHTML")); } else { web.Navigate().GoToUrl(fp.Link + string.Format("publicMes.php?public={0}&ano={1}", meses[DateTime.Now.Month - 1], DateTime.Now.Year)); Thread.Sleep(1000); return(web.FindElement(By.XPath("//*[@id='tabela1']/tbody")).GetAttribute("innerHTML")); } }
/*Registra a consulta no banco*/ private static void RegistrarConsulta(HtmlDocument htmlDocument, FontePesquisa fp) { RService.Log("(RegistrarConsulta) " + Name + ": Verificando registros... " + "at {0}", Path.GetTempPath() + Name + ".txt"); try { string htmlTratado = Regex.Replace(htmlDocument.DocumentNode.InnerHtml, @"\s*\n*", ""); string valorRegex = string.Format(@"{0}", fp.Regex); MatchCollection mt = StringHandle.GetMatches(htmlTratado, valorRegex); string conteudo = mt != null ? mt[0].Value : string.Empty; FontePesquisaRobot fpr = new FontePesquisaRobot(fp.Id); fpr.DataHoraPesquisa = DateTime.Now; fpr.Conteudo = conteudo; /*caso tenha alteração no site*/ if (!conteudo.Equals(fp.UltimoConteudo)) { if (fp.UltimoConteudo != null) { RService.Log("(RegistrarConsulta) " + Name + ": Houve alteração na fonte de pesquisa, gerado Warning... at {0}", Path.GetTempPath() + Name + ".txt"); fpr.Status = (byte)StatusAlerta.Warning; FontePesquisaRobotController.Criar(fpr); NumAlteracoes++; } fp.UltimoConteudo = conteudo; FontePesquisaController.Atualizar(fp); } /*caso não tenha alteração no site*/ else { RService.Log("(RegistrarConsulta) " + Name + ": Não houve alteração na fonte de pesquisa... at {0}", Path.GetTempPath() + Name + ".txt"); } } catch (Exception e) { RService.Log("Exception (RegistrarConsulta)" + Name + ":" + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt"); } }
//Método específico para o Diário Oficial de Itabaianinha private static string getContentDOItabaianinha(FontePesquisa fp) { string content = string.Empty; string[] element = fp.Regex.Split(';'); web.Navigate().GoToUrl(fp.Link); string year = DateTime.Today.Year.ToString("d4"); new SelectElement(web.FindElement(By.XPath(element[0]))).SelectByText(year); Thread.Sleep(2000); string month = DateTime.Today.Month.ToString("d2"); new SelectElement(web.FindElement(By.XPath(element[1]))).SelectByValue(month); Thread.Sleep(2000); var options = web.FindElement(By.XPath("//*[@id=\"body_ddlEdicao\"]")).FindElements(By.TagName("option")); int index = options.Count() - 1; content = options[index].GetAttribute("innerHTML").ToString(); return(content); }
private static string SitesComMaisProcedimentos(FontePesquisa fp) { switch (fp.Nome) { case "Diário Oficial do Maranhão": content = GetContentDOMaranhao(fp); break; case "Imprensa Oficial do Estado do Rio de Janeiro": content = GetContentIORJ(fp); break; case "Diário Oficial de Canoas - RS": content = GetContentDOCanoas(fp); break; case "Diário Oficial de Candeal - BA": case "Diário Oficial de Santaluz - BA": content = GetContentDOCandeal(fp); break; case "Diário Oficial de Pocinhos - PB": content = getContentDOPocinhos(fp); break; case "Diário Oficial de Ariranha do Ivaí - PR": case "Diário Oficial de Lidianópolis - PR": content = getContentDOAriranhaAvai(fp); break; case "Diário Oficial de Guarujá - SP": content = getContentDOGuaruja(fp); break; } return(content); }
private static void RegistrarConsulta(FontePesquisa fp) { RService.Log("(RegistrarConsulta) " + Name + ": Verificando registros... " + "at {0}", Path.GetTempPath() + Name + ".txt"); try { //Analisa a Regex para definir qual caminho seguir, o que exige mais de um clique ou o que ele consegue capturar o conteúdo de primeira content = SitesComMaisProcedimentos(fp); if (fp.Regex.Contains(';')) { string[] element = fp.Regex.Split(';'); int last = element.Count() - 1; web.Navigate().GoToUrl(fp.Link); Thread.Sleep(3000); for (int i = 0; i < last; i++) { if (element[i].Contains("frame")) { web.SwitchTo().Frame(web.FindElement(By.XPath(element[i]))); } else { web.FindElement(By.XPath(element[i])).Click(); } } content = web.FindElement(By.XPath(element[last])).GetAttribute("innerHTML").ToString(); } else { web.Navigate().GoToUrl(fp.Link); Thread.Sleep(3000); content = web.FindElement(By.XPath(fp.Regex)).GetAttribute("innerHTML").ToString(); } if (content.Contains("�") || content.Contains("\"")) { content = content.Replace("�", ""); content = content.Replace("\"", ""); } fpr = new FontePesquisaRobot(fp.Id); fpr.DataHoraPesquisa = DateTime.Now; fpr.Conteudo = content; //Usando o valor obtido no if-else anterior, é registrada a alteração no banco if (!content.Equals(fp.UltimoConteudo)) { if (fp.UltimoConteudo != null) { RService.Log("(RegistrarConsulta) " + Name + ": Houve alteração na fonte de pesquisa, gerado Warning... at {0}", Path.GetTempPath() + Name + ".txt"); fpr.Status = (byte)StatusAlerta.Warning; FontePesquisaRobotController.Criar(fpr); NumAlteracoes++; } fp.UltimoConteudo = content; FontePesquisaController.Atualizar(fp); } else { RService.Log("(RegistrarConsulta) " + Name + ": Não houve alteração na fonte de pesquisa at {0}", Path.GetTempPath() + Name + ".txt"); } } catch (Exception e) { RService.Log("Exception (RegistrarConsulta) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt"); } }
public static void Atualizar(FontePesquisa fp) { FontePesquisaRepository fprepo = new FontePesquisaRepository(); fprepo.Update(fp); }