DEV Community

Cover image for Pulling Semrush AI Visibility and SEO Metrics with Python
Raven
Raven

Posted on

Pulling Semrush AI Visibility and SEO Metrics with Python

Most SEO dashboards still treat Google blue links as the whole picture. Over the past year, though, clients started asking a harder question: how often do ChatGPT, Gemini, and Google AI Overviews actually cite our domain compared to our rivals?

You can click through Semrush by hand to check this, domain by domain, or pay for API add-on units on top of a monthly seat. When you track 30 to 100 competitor domains every Monday, manual exports break down fast.

One practical alternative is running the Semrush All-in-One Scraper on Apify. It has over 4,600 users and more than 320,000 runs, and it packages four distinct modes (domain, keyword, seo_audit, and top_websites) behind one JSON interface.

What comes back in Domain Overview mode

In domain mode, a single request pulls both classic SEO totals and AI Search visibility into one flat-plus-nested JSON object:

Metric group Example fields returned
Domain authority authority_score, moz_domain_authority, moz_spam_score
Search traffic organic_traffic, total_traffic, organic_keywords, paid_traffic
Link profile backlinks, referring_domains, backlinks_list, referring_domains_list
AI Search ai_visibility, ai_mentions, ai_cited_pages, ai_search.by_llm

The ai_search.by_llm section breaks down mentions and cited pages across ChatGPT, Google AI Overview, AI Mode, and Gemini. It also includes top_cited_sources, which lists third-party sites that models frequently cite alongside a domain. For digital PR teams, that list is basically a ready-made outreach target sheet.

Semrush Scraper Apify Console input settings and structured JSON output

Row-level lists are opt-in, so you do not have to haul megabytes of nested arrays when you only need headline KPIs. Toggle include_organic_keywords, include_backlinks (up to 80 per domain via backlinks_limit), or include_referring_domains (up to 60 via referring_domains_limit) whenever you want deeper tables.

Building a weekly Python + Pandas tracker

Here is a small script using apify-client and pandas that checks a batch of SaaS competitors in the US database, grabs their Moz scores and top keywords, and saves a clean CSV snapshot.

import os
import pandas as pd
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])

run_input = {
    "mode": "domain",
    "domains": ["backlinko.com", "ahrefs.com", "moz.com", "searchengineland.com"],
    "database": "us",
    "include_moz": True,
    "include_organic_keywords": True,
    "include_backlinks": True,
    "backlinks_limit": 20,
    "concurrency": 20,
}

run = client.actor("pro100chok/semrush-scraper").call(run_input=run_input)
items = list(client.dataset(run["defaultDatasetId"]).iterate_items())

rows = []
for item in items:
    by_llm = {
        entry["llm"]: entry.get("mentions", 0)
        for entry in item.get("ai_search", {}).get("by_llm", [])
    }
    rows.append({
        "domain": item.get("domain"),
        "authority_score": item.get("authority_score"),
        "organic_traffic": item.get("organic_traffic"),
        "referring_domains": item.get("referring_domains"),
        "ai_visibility": item.get("ai_visibility"),
        "chatgpt_mentions": by_llm.get("ChatGPT", 0),
        "ai_overview_mentions": by_llm.get("AI Overview", 0),
        "moz_da": item.get("moz_domain_authority"),
    })

df = pd.DataFrame(rows).sort_values("ai_visibility", ascending=False)
df.to_csv("weekly_seo_ai_snapshot.csv", index=False)
print(df.to_string(index=False))
Enter fullscreen mode Exit fullscreen mode

Notice concurrency: 20. Because the actor accepts up to 100 domains per run, a 50-domain agency portfolio finishes in one short job instead of looping through single-domain requests.

Three other modes worth knowing

If you already have this actor wired into your pipeline, you can reuse the exact same API call pattern for three adjacent tasks:

  • keyword: Pass up to 100 terms in keywords and pick a regional database (90+ countries or worldwide). You get search volume, CPC, Keyword Difficulty, search intent, 12-month trend data, related questions, and live SERP snapshots.
  • seo_audit: Pass exact page URLs to inspect HTTP status, response_time_ms, h1_count, word_count, images_missing_alt, canonical, has_robots_txt, and has_sitemap right next to the domain's Semrush organic context.
  • top_websites: Pull the top 100 trending websites by country_top_websites and industry_top_websites for market sizing.

Pay-per-result pricing vs. a fixed seat

Instead of paying a recurring monthly subscription just to export a few hundred rows, billing is strictly pay-per-event on each dataset result returned: $4.00 per 1,000 results on paid Apify plans ($15.00 per 1,000 on the free tier).

Semrush Scraper cost comparison against standard SaaS pricing and pay-per-event rates

For a weekly check of 50 domains (200 results a month), that comes out to roughly $0.80 a month on a paid Apify plan. Even if you run quarterly audits on 1,000 domains, you only spend $4.00 and keep your pipeline completely serverless.

Wrapping up

If your team needs Semrush domain metrics, backlink samples, and per-LLM AI Search visibility inside Python notebooks, Looker Studio, or automated Slack alerts, give the Semrush All-in-One Scraper a test run on five of your own URLs first. Inspect the nested JSON once, map the columns you care about, and schedule it to run while you sleep.

Top comments (0)