Python Selenium scrape the price which is contained in a custom attribute

Issue

After hours of trying I manage to scrape data from a marketplace with selenium.
With this code here I took the titles

website = 'https://www.skroutz.gr/c/40/kinhta-thlefwna.html?from=families'
title_list=[]
price_list=[]
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get(website)
#titles = driver.find_elements("class name",'js-sku-link')
titles = driver.find_elements("class name",'js-sku-link')
for title in titles:
    print(title.get_attribute('title'))

I took the titles with the class name but I am curious how can I take the price which the structure is like the following screenshot.

enter image description here

What I should use in this case ?

Solution

You can use 'find_elements_by_xpath' to print the prices.

from selenium.webdriver.common.by import By
priceLink = driver.find_elements(by=By.XPATH, value = '//a[@data-e2e-testid="sku-price-link"]')

for price in priceLink:
    print(price.text)

Answered By – Himanshu Poddar

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published