@@ -17,23 +17,25 @@ def main():
1717 data = [{
1818 "target" : args .domain ,
1919 "location_code" : args .location ,
20- "language_code" : "en"
20+ "language_code" : "en" ,
21+ "limit" : 1 # We only need overview metrics
2122 }]
2223
23- response = api_post ("dataforseo_labs/google/domain_metrics_by_categories /live" , data )
24+ response = api_post ("dataforseo_labs/google/ranked_keywords /live" , data )
2425 results = get_result (response )
2526
2627 print (f"domain: { args .domain } " )
2728 print (f"location: { args .location } " )
2829
2930 if results :
3031 for result in results :
31- metrics = result .get ("metrics" , {}).get ("organic" , {})
32- print (f"organic_traffic: { format_count (metrics .get ('etv' ))} " )
33- print (f"keywords: { format_count (metrics .get ('count' ))} " )
34- pos_1 = metrics .get ("pos_1" , 0 )
35- pos_2_3 = metrics .get ("pos_2_3" , 0 )
36- print (f"top_3_positions: { pos_1 + pos_2_3 } " )
32+ metrics = result .get ("metrics" , {})
33+ if not metrics :
34+ continue
35+ organic = metrics .get ("organic" , {})
36+ print (f"organic_keywords: { format_count (organic .get ('count' , 0 ))} " )
37+ print (f"organic_traffic: { format_count (organic .get ('etv' , 0 ))} " )
38+ print (f"top_3_positions: { organic .get ('pos_1' , 0 ) + organic .get ('pos_2_3' , 0 )} " )
3739 else :
3840 print ("No results found" )
3941
0 commit comments