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
f9b9bb39
...
f9b9bb39b65a25e91ab0a47124f0408c960271ba
authored
2011-11-30 13:29:37 -0700
by
Solomon White
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Example in which steps are not all known in advance
1 parent
33f335a6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
samples/googlepagination.coffee
samples/googlepagination.coffee
0 → 100644
View file @
f9b9bb3
# get multiple pages of google search results
#
# usage: phantomjs googlepagination.coffee my search terms
#
# (all arguments will be used as the query)
#
phantom
.
injectJs
(
'casper.js'
)
links
=
[]
casper
=
new
phantom
.
Casper
casper
.
start
'http://google.com'
,
->
@
fill
'form[name=f]'
,
q
:
phantom
.
args
.
join
(
' '
),
true
@
click
'input[value="Google Search"]'
casper
.
then
->
# google's being all ajaxy, wait for results to load...
@
waitForSelector
'table#nav'
,
->
processPage
=
(
cspr
)
->
currentPage
=
Number
cspr
.
evaluate
(
->
document
.
querySelector
(
'table#nav td.cur'
).
innerText
),
10
currentPage
=
1
if
currentPage
==
0
cspr
.
capture
"google-results-p
#{
currentPage
}
.png"
# don't go too far down the rabbit hole
return
if
currentPage
>=
5
cspr
.
evaluate
->
if
nextLink
=
document
.
querySelector
(
'table#nav td.cur'
).
nextElementSibling
?
.
querySelector
(
'a'
)
nextLink
.
setAttribute
'id'
,
'next-page-of-results'
nextPage
=
'a#next-page-of-results'
if
cspr
.
exists
nextPage
cspr
.
echo
'requesting next page...'
cspr
.
thenClick
(
nextPage
).
then
(
processPage
)
else
cspr
.
echo
"that's all, folks."
processPage
(
casper
)
casper
.
run
->
@
exit
()
Please
register
or
sign in
to post a comment