Home > Software design >  Python Selenium scrape the price which is contained in a custom attribute
Python Selenium scrape the price which is contained in a custom attribute

Time:07-04

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 ?

CodePudding user response:

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)
  • Related