Analyzing competitor traffic and keyword gaps is essential for any SEO strategy. I wrote this function using the SerpSpur Traffic & Competitor Explorer API to compare organic keywords across multiple domains:
python
import requests
API_KEY = "your_api_key_here"
def compare_competitor_keywords(domains, country):
results = {}
for domain in domains:
response = requests.get(
f"https://api.serpspur.com/v1/traffic-explorer?domain={domain}&country={country}",
headers={"Authorization": f"Bearer {API_KEY}"}
)
data = response.json()
results[domain] = [kw["keyword"] for kw in data.get("organic_keywords", [])[:20]]
return results
Example usage
competitors = ["competitor1.com", "competitor2.com"]
country = "US"
keyword_sets = compare_competitor_keywords(competitors, country)
for domain, keywords in keyword_sets.items():
print(f"\n{domain} top keywords:")
for kw in keywords:
print(f" - {kw}")
This helps identify keywords your competitors rank for that you don't. I've found it particularly useful for finding low-hanging fruit in niche markets. What's your approach to competitor keyword research?
```
Top comments (0)