suryasev / unofficial-google-trends-api

Python-based API that uses the http site to download Google Trends data
http://www.juiceanalytics.com/openjuice/programmatic-google-trends-api/
215 stars 70 forks source link

csv fails #8

Open timnugent opened 11 years ago

timnugent commented 11 years ago

Has anyone had any joy with this code recently? I've changed the csv url as per the message below. I now hit this exception on calling print connector.csv():

"Could not find requested section"

If I comment that out and just return s in the previous loop, the output looks like this:

An error has been detected. This page is currently unavailable. Please try again later. Please make sure that your query is valid and try again. If you're experiencing long delays, consider reducing your comparison items. Thanks for your patience. ©2013 Google

Any help much appreciated,

Thanks, Tim

timnugent commented 11 years ago

Looks like the parameters have changed. To get a csv file you need to do this (some of the other params work too but I didn't experiment much:

    params = urllib.urlencode({
        'q': ",".join(keywords),
        'content': 1,
        'export': 1
    })      

Cheers, Tim

mrtndwrd commented 11 years ago

I'm experiencing more or less the same problem. I added the parameters, but I still get the following. "Omleiding" is dutch for "redirection"

<html><head><title>Omleiding</title>

<script type="text/javascript" language="javascript">
      // Accessing window.external members can cause IE to throw exceptions.
      // Any code that acesses window.external members must be try/catch wrapped
      /** @preserveTry */
      try {
        if (top == self) {
          if (window.gtbExternal) {
            window.gtbExternal.setM();
          } else {
            window.external.setM();
          }
        }
      }
      catch(err) {
      }
    </script>
<meta http-equiv="refresh" content="0; url=&#39;http://www.google.com/trends#content=1&amp;q=depression&#39;"></head>
<body bgcolor="#ffffff" text="#000000" link="#0000cc" vlink="#551a8b" alink="#ff0000"><script type="text/javascript" language="javascript">
    location.replace("http://www.google.com/trends#content\x3d1\x26q\x3ddepression")
  </script></body></html>
timnugent commented 11 years ago

Did you also change the download url to:

http://www.google.com/trends/trendsReport

?

mrtndwrd commented 11 years ago

Well, I did now, on lines 27, 39 and 86, but with no use. Same result

Edit: Oh, I'm truly sorry. I had to change my password for this (google didn't believe I would want to do an authentication attempt with python). I forgot to change it in my script, so that's why it didn't work. At least now we know the error message for a failed login attempt.

simon-cd commented 11 years ago

The data coming out of this API is not matching the data you get when you download it directly from Google Trends using Google's "Download to CSV" feature.

What else needs to be updated in the API to get the right data?

simon-cd commented 11 years ago

I found the problem. You have to search one word at a time otherwise the words are rescaled. My apologizes.