Created
October 25, 2018 22:55
-
-
Save matthlavacka/11140cd198be799d5925b8e8a74b6de6 to your computer and use it in GitHub Desktop.
Revisions
-
matthlavacka created this gist
Oct 25, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ var links = []; 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'); }); } casper.start('http://google.fr/', function() { // Wait for the page to be loaded this.waitForSelector('form[action="/search"]'); }); casper.then(function() { // search for 'drake' from google form this.fill('form[action="/search"]', { q: 'drake' }, true); }); casper.then(function() { // aggregate results for the 'drake' search links = this.evaluate(getLinks); }); casper.run(function() { // echo results in some pretty fashion this.echo(links.length + ' links found:'); this.echo(' - ' + links.join('\n - ')).exit(); });