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
51a03f65
...
51a03f65326cc42b1464f8121690681ba0cf791b
authored
2012-05-02 08:53:07 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixes #100 - googlepagination.coffee broken
1 parent
c465362a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
26 deletions
samples/googlepagination.coffee
samples/googlepagination.coffee
View file @
51a03f6
""" Capture multiple pages of google search results
# Capture multiple pages of google search results
#
# usage: casperjs googlepagination.coffee my search terms
#
# (all arguments will be used as the query)
usage: casperjs googlepagination.coffee my search terms
(all arguments will be used as the query)
"""
casper
=
require
(
'casper'
).
create
()
currentPage
=
1
if
casper
.
cli
.
args
.
length
==
0
casper
.
echo
"usage: $ casperjs my search terms"
casper
.
exit
()
casper
.
start
'http://google.com'
,
->
@
fill
'form[action="/search"]'
,
q
:
casper
.
cli
.
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"
processPage
=
->
casper
.
echo
"capturing page
#{
currentPage
}
"
casper
.
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
)
if
casper
.
exists
"#pnnext"
currentPage
++
casper
.
echo
"requesting next page:
#{
currentPage
}
"
casper
.
thenClick
(
"#pnnext"
).
then
(
processPage
)
else
cspr
.
echo
"that's all, folks."
casper
.
echo
"that's all, folks."
casper
.
start
'http://google.fr/'
,
->
@
fill
'form[action="/search"]'
,
q
:
casper
.
cli
.
args
.
join
(
' '
),
true
processPage
(
casper
)
casper
.
then
->
# google's being all ajaxy, wait for results to load...
@
waitForSelector
'table#nav'
,
=>
processPage
(
casper
)
casper
.
run
()
...
...
Please
register
or
sign in
to post a comment