rewrote samples/googlematch.js using Casper#each()
Showing
1 changed file
with
6 additions
and
14 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); | ||
39 | }; | ||
40 | })(self, i)); | ||
41 | self.then((function(casper, i) { | ||
42 | return function(self) { | ||
43 | var term = terms[i], score = self.fetchScore(); | ||
44 | scores.push({ | 38 | scores.push({ |
45 | term: term, | 39 | term: term, |
46 | score: score | 40 | score: score |
47 | }); | 41 | }); |
48 | self.echo(term + ': ' + score); | 42 | self.echo(term + ': ' + score); |
49 | }; | 43 | }); |
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