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
c8eba140
...
c8eba1409b7cedcb21938a0c77801292028cea6c
authored
2012-10-06 18:48:52 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
updated samples/googlelinks.js according google changes
1 parent
e6295865
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
samples/googlelinks.coffee
samples/googlelinks.js
samples/googlelinks.coffee
View file @
c8eba14
...
...
@@ -4,7 +4,10 @@ casper = require("casper").create()
getLinks
=
->
links
=
document
.
querySelectorAll
(
"h3.r a"
)
Array
::
map
.
call
links
,
(
e
)
->
e
.
getAttribute
"href"
try
(
/url\?q=(.*)&sa=U/
).
exec
(
e
.
getAttribute
(
"href"
))[
1
]
catch
e
e
.
getAttribute
"href"
casper
.
start
"http://google.fr/"
,
->
# search for 'casperjs' from google form
...
...
samples/googlelinks.js
View file @
c8eba14
...
...
@@ -4,9 +4,14 @@ var casper = require("casper").create();
function
getLinks
()
{
var
links
=
document
.
querySelectorAll
(
"h3.r a"
);
return
Array
.
prototype
.
map
.
call
(
links
,
function
(
e
)
{
return
e
.
getAttribute
(
"href"
);
try
{
// google handles redirects hrefs to some script of theirs
return
(
/url
\?
q=
(
.*
)
&sa=U/
).
exec
(
e
.
getAttribute
(
"href"
))[
1
];
}
catch
(
err
)
{
return
e
.
getAttribute
(
"href"
);
}
});
}
;
}
casper
.
start
(
"http://google.fr/"
,
function
()
{
// search for 'casperjs' from google form
...
...
@@ -28,6 +33,6 @@ casper.then(function() {
casper
.
run
(
function
()
{
// echo results in some pretty fashion
this
.
echo
(
links
.
length
+
" links found:"
);
this
.
echo
(
" - "
+
links
.
join
(
"\n - "
))
this
.
echo
(
" - "
+
links
.
join
(
"\n - "
))
;
this
.
exit
();
});
...
...
Please
register
or
sign in
to post a comment