CasperJS Evaluate function not returning Array

Q.H.

Note, I've already looked at:

Understanding the evaluate function in CasperJS

I am trying to write a simple web-scraper to download all pdf's on my professor's webpage.

Here is my code:

var casper = require('casper').create({verbose: true , logLevel: "debug" });
var url = "https://www.cs.rit.edu/~ib/Classes/CSCI264_Fall16-17/assignments.html";
casper.start(url);

var elements; 
try {
    casper.then(function(){
        try {
        // statements
        elements = this.evaluate(function(){ return __utils__.findAll('body ul li a'); });
        console.log("elements: " + elements);
        console.log(this.getCurrentUrl());

        } catch(e) {
            // statements
            console.log(e);
        }   
    });
} catch(e) {

    console.log(e);
}
casper.run();

The elements array size given back is always zero but when I put

__utils__.echo(__utils__.findAll('body ul li a').length);

I get the correct amount of links.

Is this because the evaluate function won't return an array of elements?

Any help would be appreciated.

fedevegili

Just use native js methods instead of __utils__ provided by casperjs, example:

elements = this.evaluate(function(){ return document.querySelectorAll('body ul li a'); });

I'm not sure why findAll didn't work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to call another function from the function that is passed to evaluate in CasperJS

From Dev

Returning array by function

From Dev

Returning a mutable array from a function

From Dev

Understanding the evaluate function in CasperJS

From Dev

Returning Array from function in C

From Dev

Defining a function returning an array

From Dev

Cannot navigate with casperjs evaluate and __doPostBack function

From Dev

querySelector returning null in Casperjs

From Dev

Casperjs: "TypeError: 'undefined' is not a function" if evaluate() is used in another file

From Dev

VBA Evaluate function and array formula returning range of values

From Dev

Evaluate() Function Returning Error 2023, however there is no error

From Dev

swift function returning an Array

From Dev

Evaluate absolute value of array element in function

From Dev

click() function is missing on DOM element in evaluate() in CasperJS

From Dev

How to use XPath in CasperJS' evaluate function

From Dev

Returning links inside iframe using a function in CasperJS

From Dev

Function returning a Pointer to an Array

From Dev

rows().data() function is not returning an Array

From Dev

Returning an array from a function in VBA

From Dev

Returning an Array from a Function in C

From Dev

Returning a mutable array from a function

From Dev

Understanding the evaluate function in CasperJS

From Dev

function returning array as an pointer

From Dev

casperjs evaluate not executing

From Dev

Evaluate absolute value of array element in function

From Dev

Returning links inside iframe using a function in CasperJS

From Dev

Casperjs evaluate iteration

From Dev

Excel Function returning array

From Dev

Returning links inside multiple-levels iframe using a function in CasperJS

Related Related

  1. 1

    How to call another function from the function that is passed to evaluate in CasperJS

  2. 2

    Returning array by function

  3. 3

    Returning a mutable array from a function

  4. 4

    Understanding the evaluate function in CasperJS

  5. 5

    Returning Array from function in C

  6. 6

    Defining a function returning an array

  7. 7

    Cannot navigate with casperjs evaluate and __doPostBack function

  8. 8

    querySelector returning null in Casperjs

  9. 9

    Casperjs: "TypeError: 'undefined' is not a function" if evaluate() is used in another file

  10. 10

    VBA Evaluate function and array formula returning range of values

  11. 11

    Evaluate() Function Returning Error 2023, however there is no error

  12. 12

    swift function returning an Array

  13. 13

    Evaluate absolute value of array element in function

  14. 14

    click() function is missing on DOM element in evaluate() in CasperJS

  15. 15

    How to use XPath in CasperJS' evaluate function

  16. 16

    Returning links inside iframe using a function in CasperJS

  17. 17

    Function returning a Pointer to an Array

  18. 18

    rows().data() function is not returning an Array

  19. 19

    Returning an array from a function in VBA

  20. 20

    Returning an Array from a Function in C

  21. 21

    Returning a mutable array from a function

  22. 22

    Understanding the evaluate function in CasperJS

  23. 23

    function returning array as an pointer

  24. 24

    casperjs evaluate not executing

  25. 25

    Evaluate absolute value of array element in function

  26. 26

    Returning links inside iframe using a function in CasperJS

  27. 27

    Casperjs evaluate iteration

  28. 28

    Excel Function returning array

  29. 29

    Returning links inside multiple-levels iframe using a function in CasperJS

HotTag

Archive