Copy to clipboard
{CASPERJS()}
{SOURCE()}
var titleTags = [];
var casper = require('casper').create();
function getLinks() {
var titleTags = document.querySelectorAll('h3.r a');
return Array.prototype.map.call(titleTags, function(e) {
return e.innerText;
});
}
// Set user-agent to render page like chrome
casper.userAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36');
casper.start('http://google.com/', function() {
// Wait for the page to be loaded
this.waitForSelector('form[action="/search"]');
});
casper.then(function() {
// search for 'tikiwiki groupware' from google
this.fill('form[action="/search"]', { q: 'tikiwiki groupware' }, true);
});
casper.then(function() {
// aggregate results for the 'tikiwiki groupware' search
titleTags = this.evaluate(getLinks);
});
casper.run(function() {
this.echo(titleTags.length + ' Title Tags found:');
this.echo(' - ' + titleTags.join('\n - ')).exit();
});
{SOURCE}
{CASPERJS}