Today, Google has published some Python scripts which allow an automated download of data from the Google Webmaster Tools, namely the Search Query data.
UPDATE: I created a Java version of the Search Query downloader. Any feedback would be great.
The two examples included provide a simple script to download search query data for the last month into a CSV file and another to create a Google Docs spreadsheet containing that data.
The required steps to run the scripts are documented in the Project Wiki, assuming you’ve got Python running already. The ‘selected_downloads’ variable may be extended to include the TOP_PAGES alongside the TOP_QUERIES in the download:
selected_downloads = ['TOP_QUERIES', 'TOP_PAGES']
Downloading data for all your sites
To download the search query data for all sites I have in my Google Webmaster Tools account I changed the example script as follows:
# Instantiate the downloader object downloader = Downloader() # Authenticate with your Webmaster Tools sign-in info downloader.LogIn(email, password) # Get the list of sites available sites = downloader.GetSitesList() # Initiate the download for site in sites: print site.title.text try: downloader.DoDownload(site.title.text, selected_downloads) except ValueError: print "No JSON data"
The function GetSitesList() needs to be added to downloader.py:
def GetSitesList(self): stream = self._client.request('GET', self.SITES_PATH) sites = wmt.SitesFeedFromString(stream.read()) return sites.entry
with SITES_PATH being defined as
SITES_PATH = '/webmasters/tools/feeds/sites/'
Additionally gdata.webmastertools needs to be imported, so add this line to the list of imports at the beginning of the script:
import gdata.webmastertools as wmt