Example #1
0
        public static List <Entidades.CerealComun> loopCereales(List <Entidades.CerealComun> lista)
        {
            #region Iniciar driver
            IWebDriver driver = null;
            while (!success & retry > 0)
            {
                try
                {
                    driver = General.SeleniumUtility.iniciarDriver(driver, "firefox");
                    driver.Navigate().GoToUrl("http://www.bolsadecereales.com/");
                    success = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine("CEREALES: Error al iniciar el driver");
                    retry--;
                }
            }
            #endregion

            string fechadato = driver.FindElement(By.XPath("//*[@id='flash-cotiz']/p/strong")).Text;
            int    id        = 1;
            IList <IWebElement> cerealesweb = driver.FindElements(By.XPath("//*[@id='flash-cotiz-tab']/ul/li"));

            foreach (IWebElement cerealweb in cerealesweb)
            {
                Entidades.CerealComun cereal = new Entidades.CerealComun();
                cereal.id        = id;
                cereal.fechadato = Convert.ToDateTime(fechadato);
                cereal.nombre    = cerealweb.FindElement(By.XPath(".//a")).Text;

                cereal = scrapMercados(driver, cerealweb, cereal);

                lista.Add(cereal);
                id++;
            }

            driver.Quit();

            return(lista);
        }
Example #2
0
        public static Entidades.CerealComun scrapMercados(IWebDriver driver, IWebElement cerealweb, Entidades.CerealComun cereal)
        {
            int countmercado = 1;
            IList <IWebElement> mercadosweb = driver.FindElements(By.XPath("//html//div[@id='flash-cotiz-tab']/div/div/div"));

            foreach (IWebElement mercadoweb in mercadosweb)
            {
                string nombremercado = mercadoweb.Text.ToUpper();
                switch (nombremercado)
                {
                case "DISPONIBLE":
                    cereal.disponible        = scrapMercadoDisponible(driver, cerealweb, countmercado);
                    cereal.disponible.nombre = "Disponible";
                    cereal.disponible.id     = countmercado;
                    break;

                case "FUTUROS MATBA":
                    cereal.futuros_matba        = scrapMercadoFuturosMATba(driver, cerealweb, countmercado);
                    cereal.futuros_matba.nombre = "Futuros MATba";
                    cereal.futuros_matba.id     = countmercado;
                    break;

                case "FOB MAGYP":
                    cereal.fob_magyp        = scrapMercadoFOBMAGyP(driver, cerealweb, countmercado);
                    cereal.fob_magyp.nombre = "FOB MAGyP";
                    cereal.fob_magyp.id     = countmercado;
                    break;

                case "CBOT":
                    cereal.cbot        = scrapMercadoCBOT(driver, cerealweb, countmercado);
                    cereal.cbot.nombre = "CBOT";
                    cereal.cbot.id     = countmercado;
                    break;

                case "PRECIOS MAGYP":
                    cereal.precios_magyp        = scrapMercadoPreciosMAGyP(driver, cerealweb, countmercado);
                    cereal.precios_magyp.nombre = "Precios MAGyP";
                    cereal.precios_magyp.id     = countmercado;
                    break;

                default:
                    break;
                }

                countmercado++;
            }
            return(cereal);
        }