Commit c8eba140 c8eba1409b7cedcb21938a0c77801292028cea6c by Nicolas Perriault

updated samples/googlelinks.js according google changes

1 parent e6295865
......@@ -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
......
......@@ -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();
});
......