Last active
May 11, 2024 23:11
-
-
Save 01yildizmustafa/f72ccfb42fc65f5b87060b2e24da9d3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.common.exceptions import NoSuchElementException | |
import time | |
browser = webdriver.Firefox() | |
browser.get("https://amazon.com.tr") | |
wait = WebDriverWait(browser, 40) | |
ayrıntı = wait.until(EC.element_to_be_clickable((By.ID, 'sp-cc-accept'))) | |
ayrıntı.click() | |
time.sleep(3) | |
search_bul = wait.until(EC.visibility_of_element_located((By.ID, 'twotabsearchtextbox'))) | |
search_bul.click() | |
search_bul.send_keys("elektronik") | |
time.sleep(5) | |
ara = wait.until(EC.element_to_be_clickable((By.ID, 'nav-search-submit-button'))) | |
ara.click() | |
time.sleep(3) | |
ürün_sayısı = 20 # Ürün sayısını belirleyin, örnek için burada 10 kullanılmıştır. | |
a = browser.find_element(By.ID, "deneme") | |
for i in range(2, ürün_sayısı + 1): | |
try: | |
# //*[@id="search"]/div[1]/div[1]/div/span[1]/div[1]/div[18] | |
ürün_xpath = f"//*[@id='search']/div[1]/div[1]/div/span[1]/div[1]/div[{i+1}]" | |
ürün = wait.until(EC.visibility_of_element_located((By.XPATH, ürün_xpath))) | |
ürün.click() | |
time.sleep(7) | |
try: | |
kutucuk = browser.find_element(By.ID, "unqualifiedBuyBox") | |
browser.back() | |
continue # Ürüne satın alma uygun değilse diğer ürüne geç | |
except NoSuchElementException: | |
pass # Ürüne satın alma uygun ise devam et | |
# İstenmeyen tasarımı kontrol et | |
tıklanınca_düzelen_satıcı_ismi = browser.find_elements(By.XPATH, "//*[@id='newAccordionRow_1']/div/div[1]") | |
if not tıklanınca_düzelen_satıcı_ismi: | |
satıcı_ismi = wait.until(EC.presence_of_element_located((By.XPATH, "//*[@id='merchantInfoFeature_feature_div']/div[2]/div/span"))) | |
if satıcı_ismi.text != "Amazon.com.tr": | |
print() | |
print() | |
print() | |
print("Satıcı İsmi: ", satıcı_ismi.text) | |
satıcıya_git = wait.until(EC.presence_of_element_located((By.ID, "sellerProfileTriggerId"))) | |
satıcıya_git.click() | |
time.sleep(7) | |
try: | |
section1 = browser.find_element(By.XPATH, "//*[@id='spp-expander-about-seller']/div") | |
print(section1.text) # Detayları yazdır | |
except NoSuchElementException: | |
print("Satıcı hakkındakiler bulunamadı.") | |
try: | |
section2 = browser.find_element(By.XPATH, "//*[@id='page-section-detail-seller-info']") | |
print(section2.text) # Detayları yazdır | |
except NoSuchElementException: | |
print("Satıcı bilgileri bulunamadı.") | |
browser.back() # Önceki sayfaya dön | |
time.sleep(7) | |
else: | |
print() | |
print() | |
print() | |
print("Satıcı Amazon Türkiye") | |
print() | |
print() | |
print() | |
time.sleep(7) | |
browser.back() # Ürün listesine dön | |
browser.execute_script("window.scrollBy(0, 40);") | |
time.sleep(10) | |
except NoSuchElementException: | |
print(f"{i}. ürün bulunamadı.") | |
except Exception as e: | |
print(f"{i}. üründe hata: {e}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment