When we say "inspect" Chrome, it finds the jpg file and let's copy the xpath. When I try to import it in python, it comes as base64. When I decode the code, a small white image comes up. A blank image appears.
import base64
from io import BytesIO
from PIL import Image
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
def base64_to_image(base64_string):
image_data = base64.b64decode(base64_string)
image = Image.open(BytesIO(image_data))
return image
options = Options()
options.add_argument("--disable-notifications")
options.add_experimental_option("excludeSwitches", ["enable-automation"]) #blutoot hata giderme
options.add_experimental_option("useAutomationExtension", False)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.implicitly_wait(5)
driver.set_window_size(800, 200)
driver.get('https://www.migros.com.tr/sut-kahvaltilik-c-4?sayfa=1')
elems = driver.find_element(By.XPATH,"/html/body/sm-root/div/main/sm-product/article/sm-list/div/div[4]/div[2]/div[4]/sm-list-page-item[1]/mat-card/div[1]/fe-product-image/a/img")
#<img _ngcontent-ohx-c159="" felazyload="" alt="Yumurtacım 15'li L Boy Yumurta (63-72 G)" src="https://images.migrosone.com/sanalmarket/product/20001975/20001975-cdebd9.jpg" class="ng-star-inserted">
print(elems.get_attribute("src"))
# Base64 kodunu buraya girin
base64_string = elems.get_attribute("src").replace("data:image/png;base64,","")
decoded_image = base64_to_image(base64_string)
# Resmi göstermek için
decoded_image.show()