Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
71c7e2c7
...
71c7e2c7d65ebcf02f9c9dbfd0775e7a42dfa157
authored
2013-04-06 10:34:09 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixed googlepagination code sample
1 parent
81f8744b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
30 deletions
samples/googlepagination.coffee
samples/googlepagination.js
samples/googlepagination.coffee
View file @
71c7e2c
...
...
@@ -6,7 +6,11 @@ Usage: $ casperjs googlepagination.coffee my search terms
(all arguments will be used as the query)
###
casper
=
require
(
"casper"
).
create
()
casper
=
require
(
"casper"
).
create
(
waitTimeout
:
1000
pageSettings
:
userAgent
:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20130404 Firefox/23.0"
)
currentPage
=
1
if
casper
.
cli
.
args
.
length
is
0
...
...
@@ -14,27 +18,28 @@ if casper.cli.args.length is 0
.
echo
(
"Usage: $ casperjs googlepagination.coffee my search terms"
)
.
exit
(
1
)
terminate
=
->
@
echo
(
"that's all, folks."
).
exit
();
processPage
=
->
@
echo
"capturing page
#{
currentPage
}
"
@
capture
"google-results-p
#{
currentPage
}
.png"
# don't go too far down the rabbit hole
return
if
currentPage
>=
5
if
@
exists
"#pnnext"
currentPage
++
@
echo
"requesting next page:
#{
currentPage
}
"
url
=
@
getCurrentUrl
()
@
thenClick
(
"#pnnext"
).
then
->
@
waitFor
(
->
url
isnt
@
getCurrentUrl
()
),
processPage
else
@
echo
"that's all, folks."
if
currentPage
>=
5
||
!
@
exists
"#pnnext"
return
terminate
.
call
casper
currentPage
++
@
echo
"requesting next page:
#{
currentPage
}
"
url
=
@
getCurrentUrl
()
@
thenClick
(
"#pnnext"
).
then
->
@
waitFor
(
->
url
isnt
@
getCurrentUrl
()
),
processPage
,
terminate
casper
.
start
"http://google.fr/"
,
->
@
fill
'form[action="/search"]'
,
q
:
casper
.
cli
.
args
.
join
(
" "
),
true
casper
.
then
processPag
e
casper
.
waitForSelector
"#pnnext"
,
processPage
,
terminat
e
casper
.
run
()
...
...
samples/googlepagination.js
View file @
71c7e2c
...
...
@@ -9,7 +9,12 @@
* (all arguments will be used as the query)
*/
var
casper
=
require
(
"casper"
).
create
();
var
casper
=
require
(
"casper"
).
create
({
waitTimeout
:
1000
,
pageSettings
:
{
userAgent
:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20130404 Firefox/23.0"
}
});
var
currentPage
=
1
;
if
(
casper
.
cli
.
args
.
length
===
0
)
{
...
...
@@ -19,28 +24,28 @@ if (casper.cli.args.length === 0) {
;
}
var
terminate
=
function
()
{
this
.
echo
(
"that's all, folks."
).
exit
();
};
var
processPage
=
function
()
{
var
url
;
this
.
echo
(
"capturing page "
+
currentPage
);
this
.
capture
(
"google-results-p"
+
currentPage
+
".png"
);
// don't go too far down the rabbit hole
if
(
currentPage
>=
5
)
{
return
;
if
(
currentPage
>=
5
||
!
this
.
exists
(
"#pnnext"
)
)
{
return
terminate
.
call
(
casper
)
;
}
if
(
this
.
exists
(
"#pnnext"
))
{
currentPage
++
;
this
.
echo
(
"requesting next page: "
+
currentPage
);
url
=
this
.
getCurrentUrl
();
this
.
thenClick
(
"#pnnext"
).
then
(
function
()
{
this
.
waitFor
(
function
()
{
return
url
!==
this
.
getCurrentUrl
();
},
processPage
);
});
}
else
{
this
.
echo
(
"that's all, folks."
);
}
currentPage
++
;
this
.
echo
(
"requesting next page: "
+
currentPage
);
url
=
this
.
getCurrentUrl
();
this
.
thenClick
(
"#pnnext"
).
then
(
function
()
{
this
.
waitFor
(
function
()
{
return
url
!==
this
.
getCurrentUrl
();
},
processPage
,
terminate
);
});
};
casper
.
start
(
"http://google.fr/"
,
function
()
{
...
...
@@ -49,6 +54,6 @@ casper.start("http://google.fr/", function() {
},
true
);
});
casper
.
then
(
processPag
e
);
casper
.
waitForSelector
(
'#pnnext'
,
processPage
,
terminat
e
);
casper
.
run
();
...
...
Please
register
or
sign in
to post a comment