Can use casperjs facebook login, but capture to png only shows navbar

Can use casperjs facebook login but capture in png only shows navbar this is my code: facebook.js

casper.start("http://www.facebook.com/login.php", function(response) {
    if (this.exists('[name="lsd"]')) {              
        this.page.evaluate(function(a,b) {
              document.querySelector("input[name='email']").value = a
              document.querySelector("input[name='pass']").value = b;
              document.querySelector("#login_form").submit(); 
              console.log("Login submitted!");
        },user_email,user_pass);                
    } else {
        this.echo('[name="lsd"] not found', 'ERROR');
        phantom.exit();
    }
    this.capture('img/'+user_email+'_login.png');
});

casper.run();

      

please help me to solve the problem.

+3


source to share


1 answer


The problem is that you immediately commit the page after submitting the login form. You have to wait a bit for the new page to load, but that's not the only problem with facebook.

  • You need to start CasperJS like this:

    casperjs --ssl-protocol=tlsv1 facebook.js
    
          

    due to the recent POODLE SSL vulnerability. ( Another answer )

  • When you sign up for page.error

    , you see several errors popping up saying bind

    not available. You need a shim for this in order for the facebook feature to function properly. I have provided a copy paste solution here .

And now the problem of waiting for the page to load ... There are several solutions for this.

Add step

It is the simplest and works with most non-single page applications.

casper.start("http://www.facebook.com/login.php", function(response) {
    this.page.evaluate(function(a,b) {
        // login
    }, user_email, user_pass);
}).then(function(){
    this.capture('img/'+user_email+'_login.png');
}).run();

      

Wait for a selector that only exists on the new page



This is the most reliable method and works on all pages.

casper.start("http://www.facebook.com/login.php", function(response) {
    this.page.evaluate(function(a,b) {
        // login
    }, user_email, user_pass);
}).waitForSelector("SOMESELECTORLIKEPROFILEBUTTON", function(){
    this.capture('img/'+user_email+'_login.png');
}).run();

      

Wait static time

This is the least reliable but simpler one. You may wait longer than necessary or not long enough for the operation to fail.

casper.start("http://www.facebook.com/login.php", function(response) {
    this.page.evaluate(function(a,b) {
        // login
    }, user_email, user_pass);
}).wait(4000, function(){
    this.capture('img/'+user_email+'_login.png');
}).run();

      

Note. I am using the promises syntax, but this is optional.

+3


source







All Articles