I can not click on a link with phantom-node

1

I am doing scraping of the site tematika.com to be able to create a book base. The problem is that I need to go over the page but I can not, so I always get the same books. I think that with the code they will understand it better.

const phantom = require("phantom");
const cheerio = require("cheerio");

let _instance, _page;
let _books = [];

phantom.create().then(instance => {
 _instance = instance;
 return _instance.createPage();
}).then(page => {
 _page = page;
 return _page.open('http://www.tematika.com/catalogo/libros/arte__arquitectura_y_diseno--9.htm');
}).then(status => {
 console.log(status);
 return _page.property('content')
}).then(html => {
 //Transformo el html en objeto para manipularlo con cheerio
 let $ = cheerio.load(html);

 //Obtengo todos los libros y los paso a un array para recorrerlos y extraer la info que busco
 let books = $('.Gcentro').find('.moduleproductob').toArray();

 //Como siempre hay 10 paginas hago un for que itere 10 veces
 for(let i=0;i<10;i++){
 books.forEach(book => {
   let _book = {};
   _book.imageMin = $(book).find('.Gimagesproductos').attr('src');
   _book.linkBook = $(book).find('.FProductos').attr('href');
   _books.push(_book);
 });

 //En esta parte lo que yo busco es hacer click en el boton siguiente de la pagina y es lo que no me esta funcionando
//Lo que termina pasando es que nunca pasa de pagina. Entonces siempre me trae la info de los mismo 10 libros.
 _page.evaluate(function() {
   var evObj = document.createEvent('Events');
   evObj.initEvent('click', true, false);
   document.getElementById('catalogNext').dispatchEvent(evObj);
 });
}
console.log(_books);
 _page.close();
 _instance.exit();
}).catch(e => console.log(e));

What I need is to be able to do click in next and be able to bring me the books that are showing. If it is not with phantom-node and cheerio can be with another tool, the only thing I need is that it works in node .

    
asked by Exequiel Demaio 01.04.2017 в 19:56
source

0 answers