Google SERP checker Python script
What's really cool about on-page SEO is its feedback loop. Because, as soon as your changes are indexed, you can see an effect in Google's search results.
You either moved up a bit or down. So you learn if Google liked your changes or not.
With this learning you can apply more changes, get them indexed again and work your way steadily up the SERPs.
Nice - but there is one challenge.
For keyword optimization in a foreign country, you will need a VPN to see the local SERP exactly the way it would look like in that country.
So I did that for a while, but it turned out to be too cumbersome.
I had to change my IP manually each time and then count through the results. It took a lot of time, so I needed a better solution.
My keyword rank tracker would only give me data that was from 12 to 48 hours ago, so that was no solution either. I wanted to know my rankings now and if possible for free, because I'm a freelance SEO and want to keep costs in control.
Recently, I had a look at some SEO API services and noticed that many had a free tier included.
Shortly after, I also stumbled upon Google Colab to write and easily share Python scripts and enjoyed the development experience right from the beginning.
Hence, I built an SEO rank checker script in Python that would instantly check a keyword ranking. It works directly from Google Colab, so no setup-hassle.
This is how it looks like, when you fetch a SERP for a keyword in the UK:
You can use the code too if you follow below steps.
How to get started
- Sign up for the free tier on Serpstack.com - The free tier allows for 100 requests per month. It’s an affiliate link. If you ever decide to move to the paid plan, I'll get a commission.
- Copy the API key from the Serpstack dashboard.
- Make a copy of my Google Colab Python script
- Open your copy and fill out the form:
api_key- enter the key you copied from Serpstack's dashboard
target_query- your keyword
target_domain- the domain you want to find, like example.com
google_domain- the Google domain you want to search from, like google.co.uk
country_code- country code. Here the complete list following the ISO 3166 standard and a few examples:
Country Country Code Germany de USA us UK gb Denmark dk Sweden se
language- Language code. Here the complete list following ISO 639-1 standard and a few examples:
Country Language Code Germany de USA en UK en Denmark da Sweden sv
results- number of results to scrape, from 10 to max. 100
device- the search device (mobile, desktop, tablet)
- Go to the navigation bar and click on Runtime > Run all
After a few seconds a result should be logged to the bottom of the screen, that looks something like this:
How to use the script to check your website rankings?
Don't get me wrong. The idea is not to replace rank tracker tools. Among the most important SEO tools, it is necessary to have a tool that checks Google rankings accurately and immediately.
Because keyword trackers only give you the search results with a 24h delay. You don't know your website rankings now.
Why do you have to know your SERP results on-demand?
As soon as search engines index changes on your website, the page rankings update. So you want to check keyword rankings right before you publish on-page optimizations and right after - for your custom reporting.
The new organic results will indicate if your update was helpful to rank higher for your search query or not.
So this SERP checker tool is intended to be used to quickly check rank updates, and not to track rankings over time.
In my experience, this is a very rewarding methodology to work your way up into the top 10 Google results. You get feedback after each update and use the Google results themselves to tell you what works and whatnot.
Get instant SERP data for specific locations
You may have had the problem, that you work for international clients and have to check their organic results from a different city or country.
You can not simply search from your location, due to different SERPs based on the country you search from.
So the great solution to the problem is to use an API with a script that takes care of getting a local IP for the Google SERP.
You can just select the Google region you need and then let the tool check the data.
Additionally, you also get data about the related keywords, ad rankings and local pack results. And you can search with a mobile browser or get a SERP overview for desktop.
So the idea here is to make use of such services because they already solve many little problems you would otherwise encounter doing it yourself.
So there you have it. You can instantly check your keyword rankings anywhere for free.
The code is also available in this Github repository.
Let me know on Twitter how it worked for you. ✌️