Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return array of values from evaluate method

I'm using casper.evaluate() to get an array of data from within the page. However it seems to fail to return an array (whereas returning strings work flawlessly). What might be the issue?

For clarification: the code in evaluate is:

function(){ 
    return $('#id a').map(function(i, e) { 
        return $(e).attr('href'); 
    }).get(); 
}

The .get() at the end of the call is meant to get an array instead of a jQuery object. BTW, I'm sure jQuery is available in the page.

like image 661
Capi Etheriel Avatar asked Jun 15 '26 21:06

Capi Etheriel


1 Answers

You dont need jQuery here:

casper.evaluate(function() {
    return [].map.call(__utils__.findAll('#id a'), function(node) {
        return node.getAttribute('href');
    });
});
like image 173
NiKo Avatar answered Jun 20 '26 23:06

NiKo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!