private static void InitializeUtils() { Orgaos = OrgaoRepository.FindByUF(Constants.CRJ_ESTADO_FONTE); NameToModalidade = ModalidadeController.GetNameToModalidade(); Cidades = CidadeController.GetNameToCidade(Constants.CRJ_ESTADO_FONTE); repo = new LicitacaoRepository(); Lote = LoteController.CreateLote(43, Constants.CRJ_ID_FONTE); //AlreadyInserted = LicitacaoController.GetAlreadyInserted(Constants.CRJ_HOST); }
internal static void Init() { RService.Log("(Init) " + Name + ": Começando o processamento.. at {0}", Path.GetTempPath() + Name + ".txt"); try { //Inicializa as listas e variáveis que serão usadas pelo robô CurrentPage = 1; Lote = LoteController.CreateLote(43, 1249); repo = new LicitacaoRepository(); Cidades = CidadeController.GetNameToCidade(Constants.TCMCE_UF); NameToOrgao = OrgaoController.GetNomeUfToOrgao(); NameToModalidade = ModalidadeController.GetNameToModalidade(); HtmlDocument htmlDoc = WebHandle.GetHtmlDocOfPage(string.Format(Constants.TCMCE_PAGE, CurrentPage, DateTime.Today.ToString("dd-MM-yyyy"), DateTime.Today.AddYears(1).ToString("dd-MM-yyyy")), Encoding.GetEncoding("UTF-8")); //O GetLastPage pega o código Html e o vasculha para encontrar o valor da última página int lastPage = GetLastPage(htmlDoc); while (CurrentPage != lastPage) { RService.Log("(Init) " + Name + ": Percorrendo os links da página.. " + CurrentPage + " at {0}", Path.GetTempPath() + Name + ".txt"); HtmlNode licList = htmlDoc.DocumentNode.Descendants("table").SingleOrDefault(x => x.Id.Equals("table")); foreach (var lic in licList.Descendants("tr")) { if (!lic.InnerHtml.Contains("Licitação")) { HandleCreate(lic); } } CurrentPage++; htmlDoc = WebHandle.GetHtmlDocOfPage(string.Format(Constants.TCMCE_PAGE, CurrentPage, DateTime.Today.ToString("dd-MM-yyyy"), DateTime.Today.AddYears(1).ToString("dd-MM-yyyy")), Encoding.GetEncoding("ISO-8859-1")); } } catch (Exception e) { RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt"); } }
private static void Init() { RService.Log(name + ": Começando o processamento... at {0}", logPath); try { //Inicializa as listas e variáveis que serão usadas pelo robô currentPage = 1; lote = LoteController.CreateLote(43, 1442); Cidades = CidadeController.GetNameToCidade(Constants.TCEPI_UF); NameToOrgao = OrgaoController.GetNomeUfToOrgao(); NameToModalidade = ModalidadeController.GetNameToModalidade(); alreadyInserted = LicitacaoController.GetAlreadyInserted(1442, DateTime.Today.AddMonths(-3)); GetLicitacoes(); } catch (Exception e) { RService.Log("Exception (Init) " + name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", logPath); } }
private static void Init() { RService.Log("(Init) " + name + ": Começando o processamento.. at {0}", logPath); try { Lote = LoteController.CreateLote(43, 1250); Cidades = CidadeController.GetNameToCidade(Constants.TCESE_UF); NameToOrgao = OrgaoController.GetNomeUfToOrgao(); NameToModalidade = ModalidadeController.GetNameToModalidade(); for (int i = 0; i < Constants.TCESE_MUN_CODE.Count; i++) { HandleLicitacoes(i); } //repo = new LicitacaoRepository(); //repo.Insert(licitacoes); } catch (Exception e) { RService.Log("Exception (Init) " + name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", logPath); } }
/*Inicia o processamento do robot*/ private static void Init() { RService.Log("(Init) " + Name + ": Começando o processamento.. " + "at {0}", Path.GetTempPath() + Name + ".txt"); try { ModalidadeCount = 0; Modalidades = new List <Modalidade>(); Modalidades.Add(ModalidadeController.FindById(1)); Modalidades.Add(ModalidadeController.FindById(14)); Orgao = OrgaoController.FindById(388); Lote = LoteController.CreateLote(43, 507); /*Lista das licitacoes que já existem para bec.sp.gov*/ //AlreadyInserted = LicitacaoController.GetAlreadyInserted(Constants.BEC_SITE); /*Lista das cidades para o estado*/ Cidades = CidadeController.GetNameToCidade(Constants.BEC_UF); //Define os pontos de partida List <string> urls = new List <string>(); urls.Add(Constants.BEC_LINK_MODALIDADE_2); urls.Add(Constants.BEC_LINK_MODALIDADE_5); /*Percorre cada modalidade. Como o portal BEC usa javascript para gerar as licitações, foi preciso * criar dois caminhos, uma para cada modalidade: para Carta Convite, usa-se o HtmlAgilityPack e * para Dispensa de Licitação, usa-se o Selenium (PhantomJS), que consegue lidar com javascript*/ foreach (string uri in urls) { if (!uri.Contains("Dispensa")) { GetConvites(uri); } else { GetDispensas(uri); } } if (Directory.Exists(PathEdital)) { Directory.Delete(PathEdital, true); } } catch (Exception e) { RService.Log("Exception (Init)" + Name + ":" + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt"); } finally { if (NumLicitacoes <= 0) { LoteController.Delete(Lote); } if (web != null) { web.Close(); } } }
private static void Init() { RService.Log("(Init) " + Name + ": Iniciando busca... at {0}", LogPath); try { repo = new LicitacaoRepository(); Orgaos = OrgaoRepository.FindByUF(Constants.TCERS_ESTADO_FONTE); NameToModalidade = ModalidadeController.GetNameToModalidade(); Cidades = CidadeController.GetNameToCidade(Constants.TCERS_ESTADO_FONTE); Lote = LoteController.CreateLote(43, Constants.TCERS_ID_FONTE); 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(Constants.TCERS_HOST); web.FindElement(By.XPath("//*[@id=\"t_TreeNav_1\"]/div[2]/a")).Click(); web.FindElement(By.XPath("//*[@id=\"R4830475339138649_actions_button\"]")).Click(); web.FindElement(By.XPath("//*[@id=\"R4830475339138649_actions_menu_3i\"]")).Click(); try { Actions actions = new Actions(web); actions.MoveToElement(web.FindElement(By.XPath("//*[@id=\"R4830475339138649_actions_menu_3i\"]"))).Perform(); actions.MoveToElement(web.FindElement(By.XPath("//*[@id=\"R4830475339138649_actions_menu_3_0_c9\"]"))).Perform(); web.FindElement(By.XPath("//*[@id=\"R4830475339138649_actions_menu_3_0_c9\"]")).Click(); } catch (Exception e) { RService.Log("(Exception) " + Name + ": Elemento 3 at {0}", LogPath); } Thread.Sleep(10000); var html = web.PageSource; var licits = new List <string>(); Regex licitRx = new Regex("f\\?p=(.*?)\">"); if (licitRx.IsMatch(html)) { var matches = licitRx.Matches(html); foreach (var mt in matches) { if (mt.ToString().Contains("ID_LICITACAO")) { var treatedLink = mt.ToString().Replace("\">", "").Replace("amp;", ""); licits.Add(Constants.TCERS_BASEURL + treatedLink); } } } GetLicitacoes(licits); } catch (Exception e) { RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", LogPath); } }
/*Inicia o processamento do robot*/ private static void Init() { RService.Log("(Init) " + Name + ": Começando o processamento.. " + "at {0}", Path.GetTempPath() + Name + ".txt"); try { AlreadyColected = new HashSet <long>(); /*Lista das licitacoes que já existem para bec.sp.gov*/ //AlreadyInserted = LicitacaoController.GetAlreadyInserted(Constants.BEC_SITE); /*Lista das cidades para o estado*/ Cidades = CidadeController.GetNameToCidade(Constants.BEC_UF); Modalidade = ModalidadeController.FindById(24); Orgao = OrgaoController.FindById(388); Lote = LoteController.CreateLote(43, 507); Repo = new LicitacaoRepository(); //Define os pontos de partida, uri e argumentos do post List <string> urls = new List <string>(); urls.Add(Constants.BEC_LINK_MODALIDADE_71); urls.Add(Constants.BEC_LINK_MODALIDADE_72); /*Percorre cada modalidade*/ foreach (string uri in urls) { /*Lista dos parametros do post*/ NameValueCollection post = new NameValueCollection(); /*Percorre as naturezas de cada modalidade*/ foreach (var attr in WebHandle.GetHtmlDocOfPage(uri, post).DocumentNode.Descendants("span").Where(x => x.Attributes.Contains("id") && x.Attributes["id"].Value.ToString().Contains(Constants.BEC_ID_NATUREZA))) { string urin = attr.SelectSingleNode("a").Attributes["href"].Value.ToString(); int page = 2, count = 20; /*Percorre as páginas para cada uma das naturezas (ex: 1;2;3)*/ HtmlDocument pagehtml = WebHandle.GetHtmlDocOfPage(urin, post); while (pagehtml != null && count == 20) { RService.Log("(GetOC) " + Name + ": Percorrendo os links da página.. " + (page - 1) + " at {0}", Path.GetTempPath() + Name + ".txt"); //Pega as licitações de cada página (OC's) count = GetOC(pagehtml); //Pega o html da próxima página pagehtml = WebHandle.GetHtmlDocOfPage(urin, GetFormParameters(pagehtml, page)); //Numero da proxima página page++; } } } } catch (Exception e) { RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt"); } finally { if (NumLicitacoes <= 0) { LoteController.Delete(Lote); } } }