added js version of samples/googlepagination.coffee
Showing
2 changed files
with
41 additions
and
1 deletions
... | @@ -4,7 +4,7 @@ | ... | @@ -4,7 +4,7 @@ |
4 | # | 4 | # |
5 | # (all arguments will be used as the query) | 5 | # (all arguments will be used as the query) |
6 | 6 | ||
7 | casper = require('casper').create(verbose: true, logLevel: "debug") | 7 | casper = require('casper').create() |
8 | currentPage = 1 | 8 | currentPage = 1 |
9 | 9 | ||
10 | if casper.cli.args.length == 0 | 10 | if casper.cli.args.length == 0 | ... | ... |
samples/googlepagination.js
0 → 100644
1 | var casper, currentPage, processPage; | ||
2 | |||
3 | casper = require('casper').create(); | ||
4 | currentPage = 1; | ||
5 | |||
6 | if (casper.cli.args.length === 0) { | ||
7 | casper.echo("usage: $ casperjs my search terms"); | ||
8 | casper.exit(); | ||
9 | } | ||
10 | |||
11 | processPage = function() { | ||
12 | var url; | ||
13 | this.echo("capturing page " + currentPage); | ||
14 | this.capture("google-results-p" + currentPage + ".png"); | ||
15 | if (currentPage >= 5) { | ||
16 | return; | ||
17 | } | ||
18 | if (this.exists("#pnnext")) { | ||
19 | currentPage++; | ||
20 | this.echo("requesting next page: " + currentPage); | ||
21 | url = this.getCurrentUrl(); | ||
22 | return this.thenClick("#pnnext").then(function() { | ||
23 | return this.waitFor(function() { | ||
24 | return url !== this.getCurrentUrl(); | ||
25 | }, processPage); | ||
26 | }); | ||
27 | } else { | ||
28 | return this.echo("that's all, folks."); | ||
29 | } | ||
30 | }; | ||
31 | |||
32 | casper.start('http://google.fr/', function() { | ||
33 | return this.fill('form[action="/search"]', { | ||
34 | q: casper.cli.args.join(' ') | ||
35 | }, true); | ||
36 | }); | ||
37 | |||
38 | casper.then(processPage); | ||
39 | |||
40 | casper.run(); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment