10.07.2015 Views

Download pdf - Free Books

Download pdf - Free Books

Download pdf - Free Books

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Hack 63 Tracking Result Counts over TimeQuery Google for each day of a specified date range, counting the number of results at eachtime index.Sometimes the results of a search aren't of as much interest as knowing the number thereof. Howpopular a is a particular keyword? How many times is so-and-so mentioned? How do differingphrases 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, spottrends, and notice tipping points. Combining the Google API and daterange: [Hack #11] syntax isjust the ticket.This hack queries Google for each day over a specified date range, counting the number of resultsfor 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 willtend to show more results over time as Google ads more pages to its index. Second, Googledoesn't stand behind its date-range search; results shouldn't be taken as gospel.This hack requires the Time::JulianDay(http://search.cpan.org/search?query=Time%3A%3AJulianDay) Perlmodule.63.1 The Code#!/usr/local/bin/perl# goocount.pl# Runs the specified query for every day between thespecified# 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 keymy $google_key='insert key here';# Location of the GoogleSearch WSDL filemy $google_wdsl = "./GoogleSearch.wsdl";use SOAP::Lite;use Time::JulianDay;use CGI qw/:standard/;# For checking date validitymy $date_regex = '(\d{4})-(\d{1,2})-(\d{1,2})';# Make sure all arguments are passed correctly

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!