Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Optimize websites for both traditional search engines (Google, Bing) and AI engines (ChatGPT, Perplexity, Gemini)
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/serp_analysis.py
1#!/usr/bin/env python32"""3SERP analysis using DataForSEO API4Usage: python3 scripts/serp_analysis.py "best seo tools" --depth 205"""6import argparse7from dataforseo_api import api_post, get_result, print_serp_list, format_count8910def main():11parser = argparse.ArgumentParser(description="SERP analysis")12parser.add_argument("keyword", help="Search keyword")13parser.add_argument("--location", "-loc", type=int, default=2840,14help="Location code (default: 2840 = US)")15parser.add_argument("--depth", "-d", type=int, default=20, help="Search depth")16args = parser.parse_args()1718data = [{19"keyword": args.keyword,20"location_code": args.location,21"language_code": "en",22"depth": args.depth23}]2425response = api_post("serp/google/organic/live/advanced", data)26results = get_result(response)2728print(f"keyword: {args.keyword}")29print(f"location: {args.location}")3031if results:32result = results[0]33print(f"total_results: {format_count(result.get('se_results_count'))}")34items = result.get("items", [])35print_serp_list(items)36else:37print("No results found")383940if __name__ == "__main__":41main()42