Skip to content

elibus/j-google-trends-client

Repository files navigation

Java Google Trends Client (unofficial)

j-google-trends-client is a Java based implementation of Unofficial Google Trends cli based client.

Download binaries

Binaries can be downloaded here: https://github.com/elibus/j-google-trends-client/tree/master/releases/org/freaknet/gtrends/client/j-google-trends-client/

Jar files with "with-dependencies" suffix can be used straightaway as standalone application. No other dependency is needed as everything is included in the bundle.

Help

[ elibus@teresa ~ ] java -jar j-google-trends-client-1.1.1-jar-with-dependencies.jar
Sep 24, 2013 10:25:34 PM org.freaknet.gtrends.client.CmdLineParser parse
SEVERE: Missing required options: q, u, p
usage: gtclient.sh [-C <proxy>] [-d <dir>] [-l <-l>] [-m <maxRequests>]
   [-o <queryOptions>] -p <password> [-P <proxy>] -q <query> [-S
   <sleep>] [-s <section>] -u <username>
This is a client for Google Trends. It allows to:
- Download the entire CSV file (the same file that can be downloaded
through the browser)
- Download a single section of the same CSV file
- Iterate over the hierarchical tree of "Top Searches" and download
section/CSV file
 -C,--credentials <proxy>           Proxy Credentials in the form
                                    "[DOMAIN/]username:password". DOMAIN
                                    is required only for NTLM
                                    authentication
 -d,--dir <dir>                     Output directory (default: "./out")
 -l,---logLevel <-l>                Log level <INFO|WARNING|SEVERE>
                                    (default WARNING)
 -m,--maxRequests <maxRequests>     Maximum number of requests to perform.
 -o,--queryOptions <queryOptions>   Query options.
 -P,--proxy <proxy>                 Proxy host in the form
                                    "protocol://host:port" (example:
                                    http://proxy.domain.com:8080)
 -p,--password <password>           Password
 -q,--query <query>                 Google query string
 -s,--section <section>             CSV section to retrieve
 -S,--sleep <sleep>                 Sleep in ms between two different
                                    requests (might help in case the QoS
                                    threshold is exceeded - default: 0)
 -u,--username <username>           Username (example: user@google.com)
EXAMPLE: gtclient.sh -u user@google.com - p passwd -d ./outdir -q "jobs
-'steve jobs'"

Example

java -jar j-google-trends-client-1.1.1.jar -u myUser -p myPass -q "jobs -'steve jobs'" -o 'geo=IT-RM'

Hierarchical mode explained

By default the client will issue just one request for the query specified with the -q parameter. Setting the -maxRequests parameter to a integer greater than 1 will instead run the client in hierarchical mode, this means the clien will run at most -maxRequests starting from the specified word and moving on with those words found in the "Related searches" table.

Example

Run the client as follows: java -jar j-google-trends-client-1.1.1.jar -u myUser -p myPass -q "jobs -'steve jobs'" -m 100

and the client will:

  1. Download the data for the "jobs -'steve jobs'" search
  2. Add the searches in "Related searches": online jobs, nhs jobs, nhs, part time jobs, government jobs, london jobs, bank jobs
  3. Download the data for online jobs
  4. Add the searches in "Related searches"
  5. Download the data for nhs jobs
  6. ...and so on until 100 is reached.

Beware: a default lag of 1 second between one request and the next one is required to avoid flooding Google and being banned for a short amount of time. This might be customised using the -S option.

How to use --queryOptions

You might want to customise you query with additional parameters like you do with in the Google Trends page. This is possible using the o,--queryOptions <queryOptions> Query options. To discover which parameters are available and how to use them:

  1. Login into Google Trends
  2. Perform a search
  3. Set you query parameters
  4. Have a look at the URL shown by the browser

Example

Expected output:

  • Search: fortune
  • Year: 2013
  • Location: Italy

This is the URL generated by Google: http://www.google.com/trends/explore#q=fortune&geo=IT&date=1%2F2013%2012m&cmpt=date

This is how to run it: java -jar jclient.jar -u myUser -p myPass -q "jobs -'steve jobs'" -o 'geo=IT&date=1%2F2013%2012m&cmpt=date'

LICENSE

j-google-trends-api Java based implementation of Unofficial Google Trends API Copyright (C) 2013 Marco Tizzoni

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

About

Java Client for Google Trends

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages