URL Inspection API ile dizin durumunu toplu kontrol etmek

Search Console'daki "URL denetimi" aracı tek tek çalışıyor. Aynı bilgiyi API ile günde 2.000 URL'ye kadar toplu alabilirsin: dizinde mi, en son ne zaman tarandı, Google hangi canonical'ı seçti?

Kurulum Search Console API yazısındaki ile aynı: servis hesabı, JSON anahtarı ve Search Console'da kullanıcı yetkisi.

inspect_urls.py
import csv
import time
from google.oauth2 import service_account
from googleapiclient.discovery import build

SITE = "sc-domain:ornek.com"
creds = service_account.Credentials.from_service_account_file(
    "anahtar.json", scopes=["https://www.googleapis.com/auth/webmasters.readonly"])
gsc = build("searchconsole", "v1", credentials=creds)

urls = [u.strip() for u in open("urller.txt", encoding="utf-8") if u.strip()]

with open("dizin-durumu.csv", "w", newline="", encoding="utf-8") as f:
    w = csv.writer(f)
    w.writerow(["url", "durum", "son_tarama", "google_canonical", "kullanici_canonical"])
    for url in urls:
        r = gsc.urlInspection().index().inspect(
            body={"inspectionUrl": url, "siteUrl": SITE}).execute()
        idx = r["inspectionResult"]["indexStatusResult"]
        w.writerow([url, idx.get("coverageState"), idx.get("lastCrawlTime", "-"),
                    idx.get("googleCanonical", "-"), idx.get("userCanonical", "-")])
        time.sleep(0.5)  # dakikada 600 istek sınırı

print("tamam")

En ilginç sütun: canonical

google_canonical ile kullanici_canonical farklıysa, Google senin canonical tercihini kabul etmemiş demektir. Genelde sebebi şunlardan biri:

  1. İki sayfanın içeriği neredeyse aynı
  2. İç bağlantılar canonical'ı değil öteki adresi gösteriyor
  3. Sitemap'te canonical olmayan adres var

Bu listeyi ayda bir çıkarmak, "neden bu sayfa görünmüyor" sorusunun cevabını çoğu zaman kendiliğinden veriyor.

Comments / questions

If you have a question about any topic or wish to contact me: Telegram or send an email to [email protected] Thanks!

Related pages