mongodbfirebasemongoosescreen-scrapingx-ray

how to store data from .write x-ray to mongodb or firebase


i m looking for a way to write the data to firebase or mongodb using mongoose after scraping it using xray. my code is similar to the exemple below , i just need to insert it to mongoose instead of result.json on localhost. firebase is also another alternative if there is a way to perform this please

var Xray = require('x-ray');
var x = Xray();

x('https://blog.ycombinator.com/', '.post', [{
  title: 'h1 a',
  link: '.article-title@href'
}])
  .paginate('.nav-previous a@href')
  .limit(3)
  .write('results.json')

thank you


Solution

  • You can save the result passing object to the database with mongoose in the callback function

    var Xray = require('x-ray');
    var x = Xray();
    
    x('https://blog.ycombinator.com/', '.post', [{
      title: 'h1 a',
      link: '.article-title@href'
    }])
      .paginate('.nav-previous a@href')
      .limit(3)
    
      (function(error, object){        // callback
      if (error) {
        console.log(error)
      }else {
        console.log('result is: ')
        console.log(object);           // object is what you want to save
      }
    })