# Moz Bulk Brand Authority Checker # # This script fetches brand authority scores for a list of domains using the Moz API. # # The script generates a CSV with the following columns: # - Domain # - Brand Authority import json import requests import pandas as pd import time from google.colab import files # Define your Moz API credentials API_TOKEN = "bW96c2NhcGUtemNZeVRuSTVwSDpBTnI0ejRpaTZPNzJTOVpXblRveHhUWGg4QTVWUlo0bQ==" API_ENDPOINT = "https://api.moz.com/jsonrpc" # Function to fetch brand authority for a domain def fetch_brand_authority(domain, scope="domain"): headers = { "x-moz-token": API_TOKEN, "Content-Type": "application/json", } data = { "jsonrpc": "2.0", "id": "48531c26-01ed-4aef-a29c-7e7c1c4e41b0", "method": "data.site.metrics.brand.authority.fetch", "params": { "data": { "site_query": { "query": domain, "scope": scope } } } } response = requests.post(API_ENDPOINT, headers=headers, data=json.dumps(data)) # Debugging: Print the raw response print(f"Raw response for domain '{domain}': {response.json()}") if response.status_code == 200: return response.json() else: error_message = response.json().get("error", {}).get("message", "Unknown error") print(f"Error fetching data for domain '{domain}': {error_message}") return None # Function to handle multiple domains def fetch_brand_authority_bulk(domains, scope="domain"): results = [] for domain in domains: if not domain.startswith("http"): domain = f"https://{domain}" print(f"Fetching brand authority for: {domain}") result = fetch_brand_authority(domain, scope) if result and "result" in result: result_data = result["result"] site_metrics = result_data.get("site_metrics", {}) brand_authority_score = site_metrics.get("brand_authority_score") print(f"Raw 'site_metrics': {site_metrics}") print(f"Extracted Brand Authority Score: {brand_authority_score}") if brand_authority_score is not None: results.append({ "Domain": result_data["site_query"]["query"], "Brand Authority": brand_authority_score }) continue print(f"No valid brand authority data found for: {domain}") results.append({ "Domain": domain, "Brand Authority": "N/A" }) time.sleep(1) return results # User inputs domains print("Enter domains (comma-separated):") input_domains = input().strip() domains = [domain.strip() for domain in input_domains.split(",")] # Fetch and display brand authority for multiple domains data = fetch_brand_authority_bulk(domains) if data: print("Brand Authority Results:") df = pd.DataFrame(data) print(df) # Save to CSV df.to_csv("moz_bulk_brand_authority_results.csv", index=False) print("Results saved as moz_bulk_brand_authority_results.csv") files.download("moz_bulk_brand_authority_results.csv") else: print("Failed to fetch brand authority data.")