Scrapping: Google Search keyword file
Mantap! Ini versi lanjutan dari script-nya, dengan fitur:
✅ FITUR:
- Input banyak keyword dari file `keywords.txt`
- Scrape hasil pencarian Google (pakai `googlesearch-python`)
- Simpan semua hasil dalam satu file `results.csv`
- Menyimpan: `Keyword`, `Hasil Ke`, dan `URL`
Persiapan:
Buat file `keywords.txt` berisi daftar kata kunci, contoh:
berita teknologi Indonesia politik Indonesia 2025 game terbaru 2025
SCRIPT PYTHON:
from googlesearch import search
import csv
import time
def load_keywords(filename):
with open(filename, 'r', encoding='utf-8') as f:
return [line.strip() for line in f if line.strip()]
def google_scrape_bulk(keywords, num_results=10, output_file='results.csv'):
with open(output_file, mode='w', newline=, encoding='utf-8') as file:
writer = csv.writer(file)
writer.writerow(['Keyword', 'Rank', 'URL'])
for keyword in keywords:
print(f"🔍 Searching for: {keyword}")
try:
results = search(keyword, num_results=num_results)
for i, url in enumerate(results):
writer.writerow([keyword, i+1, url])
time.sleep(1) # Delay agar tidak dianggap bot
except Exception as e:
print(f"❌ Error while searching '{keyword}': {e}")
print(f"\n✅ All results saved to '{output_file}'")
# Main
if __name__ == '__main__':
keywords = load_keywords('keywords.txt')
google_scrape_bulk(keywords, num_results=10)
Output
File `results.csv` seperti ini:
Keyword,Rank,URL berita teknologi Indonesia,1,https://tekno.tempo.co/... berita teknologi Indonesia,2,https://detik.com/... politik Indonesia 2025,1,...
Catatan Tambahan
- Jika hasilnya kosong atau error, coba ganti koneksi atau pakai VPN ringan.
- Google bisa memblokir IP kalau terlalu cepat — bisa tambahkan `time.sleep(2)` antar keyword untuk aman.