Python 3 Serpstack API Example to Track Position of Keywords of Website in Google SERPS in Command Line
import requests
import os
api_key = "##yourapikey##"
query = "jspdf"
target_domain = "codingshiksha.com"
google_domain = "google.com"
country_code = "in"
language = "en"
results = 50
device = "desktop"
params = {
'access_key': api_key,
'device': device,
'gl': country_code,
'hl': language,
'auto_location': '1',
'google_domain':google_domain,
'query': query,
'num': results
}
api_result = requests.get('http://api.serpstack.com/search', params)
api_response = api_result.json()
clear = lambda: os.system('clear')
clear()
for number, result in enumerate(api_response['organic_results'], start=1):
if target_domain in result['domain']:
print("=====================================================================")
print("%s. %s - %s" % (number, result['domain'], result['title']))
print("=====================================================================")
else:
print("%s. %s - %s" % (number, result['domain'], result['title']))