For all the developers who have expressed interest in getting programmatic access to the search queries data for their sites in Webmaster Tools, we’ve got some good news. You can now get access to your search queries data in CSV format using a open source Python script from thewebmaster-tools-downloads project. Search queries data is not currently available via the Webmaster Tools API, which has been a common API user request that we’re considering for the next API update. For those of you who need access to search queries data right now, let’s look at an example of how the search queries downloader Python script can be used to download your search queries data and upload it to a Google Spreadsheet in Google Docs.
Example usage of the search queries downloader Python script
1) If Python is not already installed on your machine, download and install Python.
2) Download and install the Google Data APIs Python Client Library.
3) Create a folder and add the downloader.py script to the newly created folder.
4) Copy the example-create-spreadsheet.py script to the same folder as downloader.py and edit it to replace the example values for “website,” “email” and “password” with valid values for your Webmaster Tools verified site.
5) Open a Terminal window and run the example-create-spreadsheet.py script by entering “python example-create-spreadsheet.py” at the Terminal window command line:
6) Visit Google Docs to see a new spreadsheet containing your search queries data.
If you just want to download your search queries data in a .csv file without uploading the data to a Google spreadsheet use example-simple-download.py instead of example-create-spreadsheet.py in the example above.
You could easily configure these scripts to be run daily or monthly to archive and view your search queries data across larger date ranges than the current one month of data that is available in Webmaster Tools, for example, by setting up a cron job or using Windows Task Scheduler.
An important point to note is that this script example includes user name and password credentials within the script itself. If you plan to run this in a production environment you should follow security best practices like using encrypted user credentials retrieved from a secure data storage source. The script itself uses HTTPS to communicate with the API to protect these credentials.
Take a look at the search queries downloader script and start using search queries data in your own scripts or tools. Let us know if you have questions or feedback in the Webmaster Help Forum.
Written by Jonathan Simon, Webmaster Trends Analyst
Barry Wise said…
Excellent – been waiting for this. Just curious to know why Google always seems to prefer Python over PHP
Schedule in Windows 7 http://windows.microsoft.com/en-US/windows7/schedule-a-task
Really great addition guys. Thanks! As an FYI to everyone else, I’ve found you can change the selected_downloads in the script from “TOP_QUERIES” to “TOP_PAGES” to pull you top pages report instead.
For those who like to use this to download the data for all their sites at once, I’ve changed the scripts somewhat: http://www.webkruscht.com/2011/downloading-data-from-google-webmaster-tools
DECEMBER 24, 2011 AT 8:22 AMThomas Hey’l said…This is really a great Christmas present. With a little help of JohnMu I’ve been able to pimp those scripts so their output becomes configurable with dates, regions, query types, pages or queries, etc.
Please add the mapping for TOP_QUERY_CHART and TOP_PAGES_CHART to the JSON list of downloadable files – this would really improve the tool.
DECEMBER 25, 2011 AT 7:32 AMlaborant said…Hi I’m stuck at 4) where example-create-spreadsheet.py is executed. There I get thid output:
Traceback (most recent call last):
sites_json = json.loads(available)
File “C:\Python27\lib\json\__init__.py”, lin
File “C:\Python27\lib\json\decoder.py”, line
obj, end = self.raw_decode(s, idx=_w(s, 0)
File “C:\Python27\lib\json\decoder.py”, line
raise ValueError(“No JSON object could be
ValueError: No JSON object could be decoded
The gdata python client works I’ve tested it with the example code from the installation HowTo. I’ve modified email password and website.
Does anyone has an idea?
If you’re looking for PHP support: I wrote something up here: http://code.google.com/p/php-webmaster-tools-downloads/source/browse/
I was considering using Google and you associates for web publishing and investing. However since you have now abandoned Democracy and taken the Communist view of Corporate Might is Right by going along will an Illegal bill which promotes regression, monopolization, subjugation and dictatorship. I hope you guys crash and burn for what you have done.
Seems the script is no more working for External Links and other features. Looks like the _GetDownloadList function returns just 2 or 3 downloadable URLs…
Can you point me to the documentation for tweaking these files? For example, This gives the top search queries for the past 30 days, but what if I only want data for the past week? Or yesterday? Thanks for the article!
Nice article! I realize you wrote it over 2 years ago but the scripts still work. Can you point me to any documentation showing how to change the date range? For example, what if I only want top queries for the past week, or day?
I was able to customize the date range by editing downloader.py and changing “url = self._GetFullUrl(path)” to “url = self._GetFullUrl(path + ‘&prop=WEB®ion&db=20130801&de=20130807&more=true&format=csv’)” where “db” is the beginning date” and “de” is the end date.
got it to work and it works like a charm. can anyone point me in the right direction on how to setup it up so that it creates automatic monthly exports?
Does this work with python33?
Since over a year has passed since we published this post, we’re closing the comments to help us focus on the work ahead. If you still have a question or comment you’d like to discuss, free to visit and/or post your topic in our Webmaster Central Help Forum.
Thanks and take care,
The Webmaster Central Team