DEV Community

Julia Theron
Julia Theron

Posted on

How to Test Local SEO Rankings with Python and SERP API

Ever struggled with testing local SEO changes without physically being in a different location? I found a neat trick using Python to simulate location for search result testing. Here's a simple script that uses the SERPSpur API to fetch localized SERPs:

python
import requests

API_ENDPOINT = "https://api.serspur.com/v1/search"
API_KEY = "your_api_key_here"

def get_local_results(query, location):
headers = {"Authorization": f"Bearer {API_KEY}"}
params = {"q": query, "location": location, "num": 10}
response = requests.get(API_ENDPOINT, headers=headers, params=params)
return response.json()

Example usage

results = get_local_results("best coffee shop", "New York, NY")
for result in results['organic_results']:
print(f"Title: {result['title']}")
print(f"URL: {result['link']}")
print("---")

This approach saves me from constantly switching VPNs or using browser extensions. What's your go-to method for local SEO testing? Let's share tips! 🧠

Top comments (0)