Cek SERP Real-Time Pakai Python & BeautifulSoup

187 words • 1,378 chars Markdown
Raw

Cek Peringkat SERP Otomatis

Buat lo yang males cek ranking manual satu-satu. Script Python simpel buat ngambil posisi keyword di Google tanpa tool berbayar.

Prasyarat

Install library yang dibutuhin dulu via terminal:

pip install requests beautifulsoup4 pandas

Snippet Kode

Simpan dengan nama serp_checker.py. Ganti target_domain sama query sesuai kebutuhan lu.

import requests
from bs4 import BeautifulSoup
import pandas as pd

def check_serp(query, target_domain):
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
    }
    url = f"https://www.google.com/search?q={query.replace(' ', '+')}&num=10"

    response = requests.get(url, headers=headers)
    if response.status_code != 200:
        return "Blocked"

    soup = BeautifulSoup(response.text, 'html.parser')
    results = soup.select('div.g')

    for index, result in enumerate(results, start=1):
        link = result.find('a')['href'] if result.find('a') else ''
        if target_domain in link:
            return index

    return "> 10"

# Eksekusi
keyword = "audit seo teknis"
domain = "astropaste.com"

posisi = check_serp(keyword, domain)
print(f"Keyword: {keyword} | Posisi: {posisi}")

Catatan Indra

Jangan dipake spamming request barbar ya, bro. Kena rate limit CAPTCHA Google nanti. Pake jeda time.sleep() kalo mau ngecek banyak keyword sekaligus.