Saturday, January 19, 2013

Unofficial Google Trends API

I was inspired by Sal Uryasev, who wrote the first unofficial Google Trends API and made it public. That's my fork of his repo: https://github.com/mac-r/unofficial-google-trends-api. The problem is that his code doesn't work anymore. I didn't like the idea of creating a new session as well. My script (https://github.com/mac-r/trendo) allows to get daily data per specified month without any authorization.


How to use it
Clone the repository within the following command:
$ git clone git@github.com:mac-r/trendo.git
Open the editor and specify your request:
###################################################
#  EDIT YOUR REQUEST HERE                         #
###################################################
# for phrases wirte like that: word = "my+phrase"
word = "New+Year" 
month = 1
year = 2013
Run the script in the terminal:
$ ruby trendo.rb
Use the result.csv according to your needs.

Possible problems
If you make too many requests - then you'll get banned by Googlers. So be careful.

Requirements
It works well with Ruby 1.9.3

4 comments:

  1. works great! however, is it possible to get weekly data instead of monthly data? I tried to play a little bit with the url but can't find a way that works.. thank you for your input!

    ReplyDelete
    Replies
    1. Hey, JD! I know how to look at values by each month. You simply need to remove date parameter to achieve this. It's a good question about weekly data. Please, let me know if you figure out how to do this!

      Follow me on Github, pretty soon I will roll out several new machine learning packages. Stay tuned.

      Delete
  2. I still have one problem: after like 3-4 times succesfullt retrieving data, I get the following error:

    trendo.rb:25:in `': undefined method `split' for nil:NilClass (NoMethodError)

    Any thoughts?

    ReplyDelete
    Replies
    1. You get banned by Google. That's ok. Google Trends have no developers API.

      Delete