Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Google Keyword Tool Scraper(casperjs version)
// EDIT: 2013/10/20
// google has updated its kwt UI, this script doesn't work any more!
// may be I will update this script when I have time to investigate their new Interface.
// requires
var utils = require('utils');
var casper = require('casper').create()
var casper = require('casper').create({
verbose: true,
logLevel: "debug"
// setup globals
var email = casper.cli.options['email'] || 'REPLACE THIS EMAIL';
var passwd = casper.cli.options['passwd'] || 'REPLACE THIS PASSWORD';
var keywords = casper.cli.options['keywords'] || 'iphone,cars,kindle';
keywords = keywords.split(',');
var kwurl = ''
var result = {}
var kws_list = [];
for (var j=0; j<((keywords.length-1)/50+1); j++) {
kws_list.push( keywords.slice(j*50, j*50+50) );
// login & save url
casper.thenEvaluate(function login(email, passwd) {
document.querySelector('#Email').setAttribute('value', email);
document.querySelector('#Passwd').setAttribute('value', passwd);
}, {email:email, passwd:passwd});
casper.waitForSelector(".aw-cues-item", function() {
kwurl = this.evaluate(function(){
var search =;
return ''+search+'&__o=cues&ideaRequestType=KEYWORD_IDEAS';
// control flows
function start(kwurl) {
this.start(kwurl); // we should start a new page,
// don't worry, we are still logged in
// ```` won't work here
this.waitForSelector("button.gwt-Button", function(){});
function query(kws){
document.querySelector('.sEAB').value = kws.join('\n');
}, {kws:kws});
function parseresults(){
this.waitForSelector('#gwt-debug-column-GLOBAL_MONTHLY_SEARCHES-row-0-3', function() {
var o = this.evaluate(function(){
var o = {};
var els = document.querySelectorAll('a.sCM');
for (var i=0; i<els.length; i++){
var el = els[i];
pel = el.parentElement.parentElement.parentElement.parentElement.parentElement;
o[el.textContent] = [pel.nextSibling.nextSibling.textContent, pel.nextSibling.nextSibling.nextSibling.textContent];
return o
for (var k in o){
result[k] = o[k];
// recusively call so that it runs sequentially
var current_kws = 0;
function check_kws(){
if (kws_list[current_kws] && kws_list[current_kws].length>0){
var kws = kws_list[current_kws];, kwurl);, kws);;
current_kws++; check_kws );
this.echo("All done");

This comment has been minimized.

Copy link
Owner Author

commented Sep 28, 2012


casperjs kwt.js --email='REPLACE THIS EMAIL' --password='REPLACE THIS PASSWORD' --password='KEYWODS,SEPERATED,BY,COMMA'

This comment has been minimized.

Copy link

commented Dec 16, 2012

Are the selectors of this interesting piece of code up to date and working?


This comment has been minimized.

Copy link

commented May 28, 2013

Hi, is that your code is functional ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.