zenhuman
zenhuman

Reputation: 59

For Loop in CasperJS

I'm operating a listener in CasperJS that visits a few private websites & waits for certain configurations of data. Right now, this operates adequately, but not optimally, on a numbered For loop, along these lines:

 for (var p = 20000;  p-- > 0;) {

// ... c.900 lines of code ....

}

While loops & Do-While loops don't work, due to scoping issues with several instances of Casper.then.

What I'm really looking to do is cron the code over a day timer, to operate between 6am and midnight, something like:

// as global variable

function militarytime () {
                var currentTime = new Date();
                var hours = currentTime.getHours();
                var minutes = currentTime.getMinutes();
                var military = (hours*100)+minutes
                return military;
}

var p = militarytime();

// then within code,

for (t=p; (t=p) && (p>600); t++)

This particular way of doing it (and I've tried many) just hangs in CasperJS.

The code has been operating, suboptimally, in a production environment for several weeks, and I've been searching stackoverflow & casperjs/api during that time to no avail. Any suggestions?

Thanks in advance.

Upvotes: 0

Views: 806

Answers (1)

Chris Hawkes
Chris Hawkes

Reputation: 12420

This may be a stupid question, but are you firing the run() function? I've forgotten to include that which caused my program to just hang, generally it's the only reason I've seen for it to hang without error.

Upvotes: 1

Related Questions