Google exposes a lot of information through APIs. Among these, is the information in Google Search Console. I have created a small sample program to get data from the Google Search Console API using Python to experiment with these APIs.
The code for this article can be found here.
The Google API Python client
This Python package can be used to call many different Google APIs with minimal setup. Creating the interface to the Google Search Console APIs is as simple as running
This requires you to install oauth2client
using
and to define a client_secrets.json
containing
Generating the client_id
and client_secret
can be done through Google Developers Console > Credentials.
Getting daily data for the last month
Once the interface is set up, getting the daily data is super simple:
Detailed documentation can be found here.
If you are unsure which siteUrl
to use, you can get all of them through:
This can be useful because for example domain properties are prefixed with sc-domain
and this way you can verify what the correct value is.
Creating graphs of impression data
Using Matplotlib, itβs super easy to create graphs in Python with very limited effort.
Continuing from the previous piece of code:
The first step is to iterate through the data and create a dictionary that contains the relevant data, in this case, the date and number of impressions. The next step is to create two arrays that represent the x
and y
-axis. Here all dates are transformed into a format that can be used in Matplotlib. Finally, the graph is created using Matplotlib.
The result will look something like this: