Friday 2 June 2017

Error: Can't wait without a fiber

Hello everyone i've a callback function in one route with Iron Router in my meteor project.

The issue is when i run the path localhost:3000/scraper, the console shows the below message: Error: Can't wait without a fiber

This code scrape to one page 'x'.

Router.route('/scraper', function(){
  this.response.setHeader( 'Access-Control-Allow-Origin', '*' );
  this.response.setHeader( 'Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE' );
  this.response.setHeader( 'Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, x-request-metadata' );
  this.response.setHeader( 'Access-Control-Allow-Credentials', true );

  var url = 'https://scholar.google.cl/citations?user= ... &hl=es';
  request(url, function(error, response, html){
    if(!error){
      var $ = cheerio.load(html);

      var json_pre = {  id_usuario: "",
                        autor : "",
                        imagen_usuario: ""
                     };

      $('#gsc_prf_in').filter(function(){
        var data = $(this);
        autor = data.text().trim();

        json_pre.autor = autor;
      })

      $('input[name="user"]').filter(function(){
        var data = $(this);
        id_usuario = data.val();

        json_pre.id_usuario = id_usuario;
      })

      $('#gsc_prf_pup').filter(function(){
        var data = $(this);
        imagen_usuario = data.attr('src');

        json_pre.imagen_usuario = imagen_usuario;
      })

      .....

    }

    var json = JSON.stringify(json_pre, null, 4);

    //************************************************ 


                          //Can't wait without a fiber

      var id_usuario_m = Scrapers.findOne({id_usuario :json_pre.id_usuario });
      if (id_usuario_m) {
        Scrapers.update({id_usuario :json_pre.id_usuario }, {$set: json_pre});
        console.log('Usuario Actualizado');
      } else {
        Scrapers.insert(json_pre);
        console.log('Usuario Insertado')
      }

    //************************************************


  })

  this.response.end('Fin de la scrapeada');

}, {where : "server"});

If someone could to help me, I would be be so grateful. Thanks so much to all.



via beriliox

No comments:

Post a Comment