Multiple success callbacks

53 views
Skip to first unread message

Steven Almeroth

unread,
Jun 21, 2012, 6:03:32 PM6/21/12
to phan...@googlegroups.com
First, thanks for phantomjs, its looking great.  Second, sorry for all the noob questions; but... i'm a noob.

Why is my page.open callback called twice?

If i have no phantom.exit i get:

Found 2 scripts
1. 23 window.google = {y:{}};
2. 483 function g(c){var d="undefined",a="1";if(c&&c.getE
Found 5 scripts
1. 23 window.google = {y:{}};
2. 483 function g(c){var d="undefined",a="1";if(c&&c.getE
3. 12672 (function(){try{var e=!0,h=!1;var aa=function(a,b,
4. 33 window.gbar&&gbar.eli&&gbar.eli()
5. 33 window.gbar&&gbar.elp&&gbar.elp()

but if i have a phantom.exit i get:

Found 2 scripts
1. 23 window.google = {y:{}};
2. 483 function g(c){var d="undefined",a="1";if(c&&c.getE

Here's the code:

var page = new WebPage(),

page.open(address, function (status) {
    if (status !== 'success') {
        phantom.exit(1);
    } else {
        show_scripts();
    }
    phantom.exit();  // comment this line
});

function show_scripts ( ) {
    var scripts = page.evaluate(function () {
        var a=new Array();
            s=document.getElementsByTagName("script");
        for (var i=0; i<s.length; i++) {
            a.push(s[i].innerHTML);
        }
        return a;
    });
    console.log('Found ' + scripts.length + ' scripts');
    for (var i=0; i<scripts.length; i++) {
        var s=scripts[i];
        console.log((i+1) + '. ' + s.length + ' ' + s.substr(0, 50));
    }
}

James Greene

unread,
Jul 24, 2012, 5:41:54 PM7/24/12
to phan...@googlegroups.com, sro...@gmail.com
Reply all
Reply to author
Forward
0 new messages