diff --git a/js/scraping-precios.js b/js/scraping-precios.js index 00e8a30..d5b532a 100644 --- a/js/scraping-precios.js +++ b/js/scraping-precios.js @@ -1,10 +1,11 @@ - -var respiro = 3000; +var respiro = 3000; var inicio = 0; var fin = 0; var cuantosProductos = 0; var totalIntervalos = 0; var indice = 0; +var intervalos=null; + function printConsola(texto){ var previo = ""; if($("#consola_scrapping").html()){ @@ -77,35 +78,30 @@ function getCuantosByCategoria(){ } function getIntervalos(){ - var intervalos = new Array(); - fin = 35; + var intervalosObtenidos = new Array(); + fin = 50; var intervalo = null; - while(fin <= cuantosProductos){ - intervalo = {"inicio" : inicio , "fin" : fin}; - intervalos.push(intervalo); - inicio = fin; - fin = fin + 35 ; - } - - if(fin > cuantosProductos){ - fin = fin -35; - } + while(inicio < cuantosProductos){ + if((cuantosProductos - inicio) < 50){ + var ultimo = cuantosProductos - inicio; + intervalo = {"inicio" : inicio , "fin" : ultimo}; + intervalosObtenidos.push(intervalo); + break; + }else{ + intervalo = {"inicio" : inicio , "fin" : fin}; + intervalosObtenidos.push(intervalo); + inicio+= 50 ; + } - if(fin < cuantosProductos){ - intervalo = {"inicio" : fin , "fin" : cuantosProductos}; - intervalos.push(intervalo); } - return intervalos; - + return intervalosObtenidos; } function getPrecios(){ $("#segundo_scrap").html("Ejecutando scraping en precios " + "

"); - var intervalos = getIntervalos(); - totalIntervalos = intervalos.length - 1; var categoria = $("#categoria").val(); var tienda = $("#tiendas").val(); var datos = 'prueba=precios' + '&inicio='+ intervalos[indice].inicio + '&fin='+ intervalos[indice].fin + '&categoria=' + categoria + "&shop="+tienda; @@ -133,6 +129,7 @@ function getPrecios(){ indice = 0; inicio = 0; fin = 0; + intervalos = null; } } @@ -174,6 +171,11 @@ function getCategorias(){ }); } +function setIntervalos(){ + intervalos = getIntervalos(); + totalIntervalos = intervalos.length - 1; +} + $(document).ready(function() { getCategorias(); }); \ No newline at end of file diff --git a/js/scrapping.js b/js/scrapping.js index cdacc3f..db4acf1 100644 --- a/js/scrapping.js +++ b/js/scrapping.js @@ -80,7 +80,7 @@ function getCuantosByCategoria(){ function getIntervalos(){ - var intervalos = new Array(); + var intervalosObtenidos = new Array(); fin = 50; var intervalo = null; @@ -88,17 +88,17 @@ function getIntervalos(){ if((cuantosProductos - inicio) < 50){ var ultimo = cuantosProductos - inicio; intervalo = {"inicio" : inicio , "fin" : ultimo}; - intervalos.push(intervalo); + intervalosObtenidos.push(intervalo); break; }else{ intervalo = {"inicio" : inicio , "fin" : fin}; - intervalos.push(intervalo); + intervalosObtenidos.push(intervalo); inicio+= 50 ; } } - return intervalos; + return intervalosObtenidos; } diff --git a/scrapng-precios.php b/scrapng-precios.php index d3101d0..a2c0255 100644 --- a/scrapng-precios.php +++ b/scrapng-precios.php @@ -53,8 +53,8 @@