from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
import csv
# Chrome WebDriver Yolu
driver_path = "chromedriver" # Eğer yoksa
https://chromedriver.chromium.org/downloads'den indirilebilir
driver = webdriver.Chrome(driver_path)
# Anahtar kelime girin
keywords = ["İstanbul kahveci", "Ankara oto servis"] # Anahtar kelimeler
# CSV dosyasına yazmak için
with open("sonuclar.csv", "w", newline="", encoding="utf-8") as file:
writer = csv.writer(file)
writer.writerow(["İşletme Adı", "Telefon", "Adres", "Web Sitesi"])
for keyword in keywords:
# Google'ı aç
driver.get("https://www.google.com")
search_box = driver.find_element(By.NAME, "q")
search_box.send_keys(keyword)
search_box.send_keys(Keys.RETURN)
time.sleep(2) # Sonuçların yüklenmesi için bekle
# İşletme bilgilerini çek
results = driver.find_elements(By.CLASS_NAME, "tF2Cxc")
for result in results:
try:
name = result.find_element(By.TAG_NAME, "h3").text
link = result.find_element(By.CSS_SELECTOR, "a").get_attribute("href")
print(f"İşletme: {name}, Web Sitesi: {link}")
writer.writerow([name, "Telefon bilgisi yok", "Adres bilgisi yok", link])
except Exception as e:
print("Bir hata oluştu:", e)
driver.quit()