driver = webdriver.Chrome() yerine;
driver = webdriver.Chrome("chromedriver") şeklinde kullanabilirsiniz fakat eğer ile istediğiniz değerleri alabiliyorsanız selenium kullanmak çok hantal olur.
giriş yapmak gerektiği için size çalışan bir request kodu oluşturamıyorum.
son hali aşağıda:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
import pandas as pd
from openpyxl import Workbook
from openpyxl.utils.dataframe import dataframe_to_rows
chrome_path = r'C:\chromedriver_win32\chromedriver.exe'
# WebDriver'ı başlatın ve sayfayı açın
driver = webdriver.Chrome("chrome_path")
driver.get("https://website.com")
# İşlemler için bir değişken tanımlayın
last_height = driver.execute_script("return document.body.scrollHeight")
# Tüm ürünler yüklenene kadar sayfayı kaydırın
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(1)
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
# Sayfadaki tüm ürünleri bulun
products = driver.find_elements_by_xpath("//div[@class='product-list-box']")
# Ürünleri içeren sözlük oluşturun
data = {"Product Name": [], "Product Code": [], "Price": [], "Image URL": []}
for product in products:
# Ürün adını, ürün kodunu, fiyatı ve resim URL'sini alın
name = product.find_element_by_xpath(".//h4").text
code = product.find_element_by_xpath(".//span[contains(text(),'Ürün Kodu')]/following-sibling::span").text
price = product.find_element_by_xpath(".//span[contains(@class, 'product-list-price')]/span[1]").text
img_url = product.find_element_by_xpath(".//img").get_attribute("src")
# Sözlüğe verileri ekleyin
data["Product Name"].append(name)
data["Product Code"].append(code)
data["Price"].append(price)
data["Image URL"].append(img_url)
# Sözlüğü pandas DataFrame'ine dönüştürün
df = pd.DataFrame(data)
# Excel dosyası için bir Workbook nesnesi oluşturun
wb = Workbook()
# Aktif çalışma sayfasını seçin
ws = wb.active
# DataFrame verilerini Excel sayfasına yazın
for r in dataframe_to_rows(df, index=False, header=True):
ws.append(r)
# Excel dosyasını kaydedin
wb.save('veri_data.xlsx')
# WebDriver'ı kapatın
driver.quit()Aldığım hata:
<ipython-input-13-d47de856d66c>:9: DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome("chrome_path")