rewrote samples/googlematch.js using Casper#each()
Showing
1 changed file
with
11 additions
and
19 deletions
... | @@ -30,25 +30,17 @@ if (terms.length < 2) { | ... | @@ -30,25 +30,17 @@ if (terms.length < 2) { |
30 | 30 | ||
31 | casper.start("http://google.fr/"); | 31 | casper.start("http://google.fr/"); |
32 | 32 | ||
33 | casper.repeat(terms.length, function(self) { | 33 | casper.each(terms, function(self, term, i) { |
34 | self.then((function(casper, i) { | 34 | self.then(function(self) { |
35 | return function(self) { | 35 | self.fill('form[name=f]', { q: term }, true); |
36 | self.fill('form[name=f]', { | 36 | }).then(function(self) { |
37 | q: terms[i] | 37 | var score = self.fetchScore(); |
38 | }, true); | 38 | scores.push({ |
39 | }; | 39 | term: term, |
40 | })(self, i)); | 40 | score: score |
41 | self.then((function(casper, i) { | 41 | }); |
42 | return function(self) { | 42 | self.echo(term + ': ' + score); |
43 | var term = terms[i], score = self.fetchScore(); | 43 | }); |
44 | scores.push({ | ||
45 | term: term, | ||
46 | score: score | ||
47 | }); | ||
48 | self.echo(term + ': ' + score); | ||
49 | }; | ||
50 | })(self, i)); | ||
51 | i++; | ||
52 | }); | 44 | }); |
53 | 45 | ||
54 | casper.run(function(self) { | 46 | casper.run(function(self) { | ... | ... |
-
Please register or sign in to post a comment