Tracking Result Counts over Time

Query Google for each day of a specified date range, counting the number of results at each time index.

Sometimes the results of a search aren’t of as much interest as knowing the number thereof. How popular is a particular keyword? How many times is so-and-so mentioned? How do differing phrases or spellings stack up against each other?

You may also wish to track the popularity of a term over time to watch its ups and downs, spot trends, and notice tipping points. Combining the Google API and daterange: [Hack #11] syntax is just the ticket.

This hack queries Google for each day over a specified date range, counting the number of results for each day. This leads to a list of numbers that you could enter into Excel and chart, for example.

There are a couple of caveats before diving right into the code. First, the average keyword will tend to show more results over time as Google ads more pages to its index. Second, Google doesn’t stand behind its date-range search; results shouldn’t be taken as gospel.

Tip

This hack requires the Time::JulianDay (http://search.cpan.org/search?query=Time%3A%3AJulianDay) Perl module.

The Code

#!/usr/local/bin/perl # goocount.pl # Runs the specified query for every day between the specified # start and end dates, returning date and count as CSV. # usage: goocount.pl query="{query}" start={date} end={date}\n} # where dates are of the format: yyyy-mm-dd, e.g. 2002-12-31 # Your Google API developer's key my $google_key='insert ...

Get Google Hacks now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.