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
c269f4fd
...
c269f4fdfd214ead647d9501cf960581cc68e1ef
authored
2012-06-04 15:06:45 +0200
by
Brikou CARRE
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
tweaked var declaration
1 parent
34d6e3f7
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
51 additions
and
67 deletions
samples/bbcshots.js
samples/cliplay.js
samples/dynamic.js
samples/each.js
samples/events.js
samples/extends.js
samples/googlelinks.coffee
samples/googlelinks.js
samples/googlematch.js
samples/googlepagination.js
samples/metaextract.js
samples/multirun.js
samples/screenshot.js
samples/timeout.js
samples/bbcshots.js
View file @
c269f4f
...
...
@@ -2,12 +2,11 @@
* Create a mosaic image from all headline photos on BBC homepage
*/
var
buildPage
,
casper
,
currentLink
,
images
,
nbLinks
,
next
;
casper
=
require
(
"casper"
).
create
();
nbLinks
=
0
;
currentLink
=
1
;
images
=
[];
var
casper
=
require
(
"casper"
).
create
();
var
nbLinks
=
0
;
var
currentLink
=
1
;
var
images
=
[];
var
buildPage
,
next
;
// helper to hide some element from remote DOM
casper
.
hide
=
function
(
selector
)
{
...
...
samples/cliplay.js
View file @
c269f4f
var
casper
,
dump
;
casper
=
require
(
"casper"
).
create
();
dump
=
require
(
"utils"
).
dump
;
var
casper
=
require
(
"casper"
).
create
();
var
dump
=
require
(
"utils"
).
dump
;
// removing default options passed by the Python executable
casper
.
cli
.
drop
(
"cli"
);
...
...
samples/dynamic.js
View file @
c269f4f
var
addLinks
,
casper
,
check
,
currentLink
,
links
,
searchLinks
,
start
,
upTo
;
casper
=
require
(
"casper"
).
create
({
var
casper
=
require
(
"casper"
).
create
({
verbose
:
true
});
// If we don't set a limit, it could go on forever
upTo
=
~~
casper
.
cli
.
get
(
0
)
||
10
;
var
upTo
=
~~
casper
.
cli
.
get
(
0
)
||
10
;
/*
Fetch all <a> elements from the page and return
the ones which contains a href starting with 'http://'
*/
searchLinks
=
function
()
{
var
searchLinks
=
function
()
{
var
filter
,
map
;
filter
=
Array
.
prototype
.
filter
;
map
=
Array
.
prototype
.
map
;
...
...
@@ -23,7 +21,7 @@ searchLinks = function() {
};
// The base links array
links
=
[
var
links
=
[
"http://google.com/"
,
"http://yahoo.com/"
,
"http://bing.com/"
...
...
@@ -52,7 +50,7 @@ casper.then(function() {
this
.
echo
(
"Starting"
);
});
currentLink
=
0
;
var
currentLink
=
0
;
// As long as it has a next link, and is under the maximum limit, will keep running
function
check
()
{
...
...
samples/each.js
View file @
c269f4f
var
casper
,
links
;
var
casper
=
require
(
"casper"
).
create
()
;
casper
=
require
(
"casper"
).
create
();
links
=
[
var
links
=
[
"http://google.com/"
,
"http://yahoo.com/"
,
"http://bing.com/"
...
...
samples/events.js
View file @
c269f4f
...
...
@@ -2,9 +2,7 @@
* This script will add a custom HTTP status code handler, here for 404 pages.
*/
var
casper
,
links
;
casper
=
require
(
"casper"
).
create
();
var
casper
=
require
(
"casper"
).
create
();
casper
.
on
(
"http.status.200"
,
function
(
resource
)
{
this
.
echo
(
resource
.
url
+
" is OK"
,
"INFO"
);
...
...
@@ -26,7 +24,7 @@ casper.on("http.status.500", function(resource) {
this
.
echo
(
resource
.
url
+
" is in error"
,
"ERROR"
);
});
links
=
[
var
links
=
[
"http://google.com/"
,
"http://www.google.com/"
,
"http://www.google.com/plop"
...
...
samples/extends.js
View file @
c269f4f
var
casper
,
fantomas
,
links
;
casper
=
require
(
"casper"
).
create
({
var
casper
=
require
(
"casper"
).
create
({
loadImages
:
false
,
logLevel
:
"debug"
,
verbose
:
true
});
links
=
{
var
links
=
{
"http://edition.cnn.com/"
:
0
,
"http://www.nytimes.com/"
:
0
,
"http://www.bbc.co.uk/"
:
0
,
"http://www.guardian.co.uk/"
:
0
};
fantomas
=
Object
.
create
(
casper
);
var
fantomas
=
Object
.
create
(
casper
);
fantomas
.
countLinks
=
function
()
{
return
this
.
evaluate
(
function
()
{
...
...
samples/googlelinks.coffee
View file @
c269f4f
links
=
[]
casper
=
require
(
"casper"
).
create
()
getLinks
=
->
links
=
document
.
querySelectorAll
(
"h3.r a"
)
Array
::
map
.
call
links
,
(
e
)
->
...
...
@@ -5,13 +8,13 @@ getLinks = ->
casper
.
start
"http://google.fr/"
,
->
# search for 'casperjs' from google form
@
fill
"form[action=
\"
/search
\"
]"
,
q
:
"casperjs"
,
true
@
fill
"form[action=
\"
/search
\"
]"
,
q
:
"casperjs"
,
true
casper
.
then
->
# aggregate results for the 'casperjs' search
links
=
@
evaluate
(
getLinks
)
# now search for 'phantomjs' by fillin the form again
@
fill
"form[action=
\"
/search
\"
]"
,
q
:
"phantomjs"
,
true
@
fill
"form[action=
\"
/search
\"
]"
,
q
:
"phantomjs"
,
true
casper
.
then
->
# aggregate results for the 'phantomjs' search
...
...
@@ -20,5 +23,5 @@ casper.then ->
casper
.
run
->
# echo results in some pretty fashion
@
echo
links
.
length
+
" links found:"
@
echo
(
" - "
+
links
.
join
(
"
\n
- "
)
)
@
echo
" - "
+
links
.
join
(
"
\n
- "
)
@
exit
()
...
...
samples/googlelinks.js
View file @
c269f4f
var
casper
,
getLinks
,
links
;
var
links
=
[];
var
casper
=
require
(
"casper"
).
create
();
getLinks
=
function
()
{
function
getLinks
()
{
var
links
=
document
.
querySelectorAll
(
"h3.r a"
);
return
Array
.
prototype
.
map
.
call
(
links
,
function
(
e
)
{
return
e
.
getAttribute
(
"href"
);
...
...
samples/googlematch.js
View file @
c269f4f
...
...
@@ -10,9 +10,7 @@
* winner is "nicolas" with 69600000 results
*/
var
casper
,
scores
,
terms
;
casper
=
require
(
"casper"
).
create
({
var
casper
=
require
(
"casper"
).
create
({
verbose
:
true
});
...
...
@@ -23,7 +21,7 @@ casper.fetchScore = function() {
});
};
terms
=
casper
.
cli
.
args
;
var
terms
=
casper
.
cli
.
args
;
if
(
terms
.
length
<
2
)
{
casper
...
...
@@ -32,7 +30,7 @@ if (terms.length < 2) {
;
}
scores
=
[];
var
scores
=
[];
casper
.
echo
(
"Let the match begin between \""
+
(
terms
.
join
(
'", "'
))
+
"\"!"
);
...
...
samples/googlepagination.js
View file @
c269f4f
...
...
@@ -6,10 +6,8 @@
* (all arguments will be used as the query)
*/
var
casper
,
currentPage
,
processPage
;
casper
=
require
(
"casper"
).
create
();
currentPage
=
1
;
var
casper
=
require
(
"casper"
).
create
();
var
currentPage
=
1
;
if
(
casper
.
cli
.
args
.
length
===
0
)
{
casper
...
...
@@ -18,13 +16,16 @@ if (casper.cli.args.length === 0) {
;
}
processPage
=
function
()
{
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
(
this
.
exists
(
"#pnnext"
))
{
currentPage
++
;
this
.
echo
(
"requesting next page: "
+
currentPage
);
...
...
@@ -35,7 +36,7 @@ processPage = function() {
},
processPage
);
});
}
else
{
return
this
.
echo
(
"that's all, folks."
);
this
.
echo
(
"that's all, folks."
);
}
};
...
...
samples/metaextract.js
View file @
c269f4f
var
casper
,
metas
,
url
;
casper
=
require
(
"casper"
).
create
();
url
=
casper
.
cli
.
get
(
0
);
metas
=
[];
var
casper
=
require
(
"casper"
).
create
();
var
url
=
casper
.
cli
.
get
(
0
);
var
metas
=
[];
if
(
!
url
)
{
casper
...
...
samples/multirun.js
View file @
c269f4f
var
casper
,
check
,
countLinks
,
currentSuite
,
suites
;
casper
=
require
(
"casper"
).
create
({
var
casper
=
require
(
"casper"
).
create
({
verbose
:
true
});
countLinks
=
function
()
{
var
countLinks
=
function
()
{
return
document
.
querySelectorAll
(
'a'
).
length
;
};
suites
=
[
var
suites
=
[
function
()
{
this
.
echo
(
"Suite 1"
);
this
.
start
(
"http://google.com/"
,
function
()
{
...
...
@@ -42,9 +40,9 @@ casper.then(function() {
this
.
echo
(
"Starting"
);
});
currentSuite
=
0
;
var
currentSuite
=
0
;
check
=
function
()
{
var
check
=
function
()
{
if
(
suites
[
currentSuite
])
{
suites
[
currentSuite
].
call
(
this
);
currentSuite
++
;
...
...
samples/screenshot.js
View file @
c269f4f
...
...
@@ -3,17 +3,15 @@
* Usage: $ casperjs screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>
*/
var
casper
,
filename
,
twitterAccount
;
casper
=
require
(
"casper"
).
create
({
var
casper
=
require
(
"casper"
).
create
({
viewportSize
:
{
width
:
1024
,
height
:
768
}
});
twitterAccount
=
casper
.
cli
.
get
(
0
);
filename
=
casper
.
cli
.
get
(
1
);
var
twitterAccount
=
casper
.
cli
.
get
(
0
);
var
filename
=
casper
.
cli
.
get
(
1
);
if
(
!
twitterAccount
||
!
filename
||
!
/
\.(
png|jpg|pdf
)
$/i
.
test
(
filename
))
{
casper
...
...
samples/timeout.js
View file @
c269f4f
...
...
@@ -18,9 +18,7 @@
* YES!
*/
var
casper
,
timeout
;
casper
=
require
(
"casper"
).
create
({
var
casper
=
require
(
"casper"
).
create
({
onTimeout
:
function
()
{
this
.
echo
(
"NOPE."
,
"RED_BAR"
)
...
...
@@ -29,7 +27,7 @@ casper = require("casper").create({
}
});
timeout
=
~~
casper
.
cli
.
get
(
0
);
var
timeout
=
~~
casper
.
cli
.
get
(
0
);
if
(
timeout
<
1
)
{
casper
...
...
Please
register
or
sign in
to post a comment