Lazy load scroll with nightmare JS
<p>I'm new to NightmareJS and wrote a script to scrape a website. 
This works like that. I login to my profile, wait for the site to load, then go to my likes profile and there I want to scroll down till the end of the site. At the moment I use this kind of ugly work around and wonder if there is a way to scroll down to the bottom of the page to get all results, and then go to the next step. </p>

<pre><code>var Nightmare = require('nightmare');
var vo = require('vo');
vo(run)(function(err, result) {
  if (err) throw err;
});
function *run() {
  var nightmare = Nightmare({ show: true,
                             webPreferences: { partition: 'your-custom-partition'}});
    yield nightmare
    .goto('https://facebook.com/login')
    .type('input[id="email"]', "user")
    .type("input[id='pass']", "pass")
    .click('#loginbutton')
    .wait('._8u._42ef')
    .goto('https://www.facebook.com/myprofile/likes')
    .wait(1000)
    yield nightmare
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
        .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
        .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
        .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
    .evaluate(function() {
        window.document.body.scrollTop = document.body.scrollHeight;
    })
    .wait(3000)
  var title = yield nightmare
    .evaluate(function() {
              var jsonObject = new Array('');
              var links = document.getElementsByClassName("_5rz _5k3a _5rz3 _1v6c");
              var numProfiles = links.length;
                for(var i = 0; i&lt; numProfiles; i++){
                var elem;
                elem = links[i].querySelector(".fsl.fwb.fcb a").href;
                console.log(elem);
                jsonObject.push(elem);
              }
              if(numProfiles &gt; 0) {
              //then delete that element, so we don't overlaod the page
              for(var j = 0; j &lt; numProfiles; j++){
                links[0].parentNode.removeChild(links[0]);
                }
                window.document.body.scrollTop = document.body.scrollHeight;
              }
              return jsonObject;
    });
  console.log(title);
  yield nightmare.end();
}
</code></pre>