Tutorial: How to Get Google Webmaster Tools Data on Windows With Python

The Search Query report in Google Webmaster tools is more important than ever, with the ominous (not provided) mask hiding 25%-40% of referring keyword traffic in Google Analytics. Google recently made WMT data available through an open source Python Library, making it easy to transfer that data straight into Google Docs or to your desktop, but setup and configuration isn’t easy for most.

To make it a little easier to access that data, I’ll walk you through the beginners steps to get search queries from Google Webmaster Tools using the Google Data Python Library on Windows. Expect this to take at least 15 minutes.

1. Download and install Python

First, download the Windows Installer from the Python.org official download page. At the time of writing, you’ll want the “Python 2.7.2 Windows Installer (Windows binary — does not include source).” If you have a 64-bit machine, make sure you select the “X86-64 Installer.” Once downloaded, open it up and follow the installation wizard. I recommend choosing default settings if you’re a beginner but feel free to customize if you know what you’re doing.

Installing with default settings will install Python in the C:Python27 directory. You don’t need to touch anything in there yet.

That will place the zipped “gdata-2.0.16″ folder in your C:Python27 folder, as follows: C:Python27gdata-2.0.16 , which should contain the following contents:

IMPORTANT: Now, you need to copy ALL the contents of the gdata-2.0.16 folder and paste them straight into the Python27 folder. You will probably get a popup saying that the README file already exists – you can replace it, or skip it, you don’t really need either unless you enjoy the literary merits of README files.

3. Install the Google Data API Client Library

Now it gets fun – it’s time to fire up your Windows Command Prompt by finding it in your “Accessories” folder, or by pressing Windows+R, typing “cmd” and hitting “Enter.”

Navigate into the C:Python27 folder by typing “cd Python27” without quotes.“cd” is short for “change directory,” which is how to move from one folder (directory) to another from the command line.

Now that you’re in the Python27 folder, type “python ./setup.py install” without quotes, which will install the client library. If you start seeing hundreds of scrolling lines, you’ve done everything correctly to this point.

4. Create a ‘wmt’ folder, and set up scripts

Create a folder in the Python27 folder called wmt, so that it can be found at C:Python27wmt

Download and place the downloader.py script in the new wmt folder (either copy the code from that page into a new file and save it as downloader.py, or right click the “view raw file” link on that page and save it to the folder).

Find the highlighted fields and replace them with your Webmaster Tools user credentials and website, then save (Ctrl+s):

email

password

website

5. Open the command line and start getting Search Query reports

Now that C:Python27wmtexample-create-spreadsheet.py has been updated with your website of choice, along with your Webmaster Tools username and password, open your Command Line prompt, (make sure you’re still working in the C:Python27 directory), and type in this command:

python ./wmt/example-create-spreadsheet.py

After several seconds you will see a message that says “Spreadsheet now accessible online at: https://docs.google.com/spreadsheet/….,” and you can access the CSV file at that URL or by logging into Google Docs!

That’s it!

If you would rather download it directly to your desktop rather than transferring the data to Google Docs, use example-simple-download.py instead.

6. Handy tip

The example-create-spreadsheet.py code provided for Google is great if you consistently pull search query data from only one website, but if you’re like me and you need to easily pull reports for multiple websites, I recommend downloading my modified version: sq-report.py (right click->Save as…). Everything is the same except for the website field, which you can now call from the command line like so:

python ./wmt/sq-report.py http://www.seo.com/

Replace http://www.seo.com/ with any website your Webmaster Tools account has access to – and don’t forget to edit the sq-report.py file with your username and password.

Now you can easily pull a report for any site you have access to, without editing the Python file every time!

7. Conclusion

I will follow up with instructions for automating this every month for compiling historic data, as Google Webmaster Tools only provides the past 30 days of data.

I hope this is helpful for the average Windows user who may find it trick to install and work with Python code, let me know how it goes and if you run into problems, contact me on Twitter or in the comments so I can help you troubleshoot.

About Claye Stokes

Claye has always been passionate about business, web technologies, and marketing. Professionally, he has worked for both SEO agencies and full service ad agencies. As a result, his experience ranges from managing the online presence and SEO for small- to enterprise-level companies, to working side by side with business owners to fulfill their entire marketing and advertising campaigns, both on and off the web.

When he isn't working or spending time with his beautiful wife and two children, you will probably find him researching and practicing online marketing techniques, or outdoors practicing his golf swing.

Thanks for the walk through. It was very easy to follow and I got it working in no time. One quick question – is there a similar method to use to pull all the crawl errors on the site – I’ve been searching and haven’t found any guides on how to do this, except for Vanessa Fox’s article on Search Englie Land, which says you can do this but doesn’t tell you how. It would be awesome if you could point me in the right direction.

Hy! I saw that you have not accepted my first comment. Please, if you have some time, help me. I did as you written in the article and in the end I get this error:
AttributeError: ‘function’ object has no attribute ‘func_name’
Thank you!