Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to extract content using selenium

I’m unable to print price of the selenium object using class attribute extracted from the page. Using the same class I can extract from some products, but not for all. What is the mistake I’m doing here?

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

chrome_options = Options()
chrome_options.add_experimental_option("detach", True)

driver = webdriver.Chrome(options=chrome_options)

driver.get('https://www.amazon.in/Nothing-Phone-Black-128-RAM/dp/B0BKZVF7VV/ref=sr_1_2?crid=2V22OHL4YXGHF&keywords=nothing+phone+1&qid=1678089940&sprefix=nothing%2Caps%2C209&sr=8-2')

price_element = driver.find_element(By.CLASS_NAME, "a-offscreen")
print(price_element.text)

driver.quit()

I was expecting the print statement should provide the price of the product.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This selector

price_element = driver.find_element(By.CLASS_NAME, "a-offscreen")

selects multiple elements.

To get precisely price of the main product try using this

price_element = driver.find_element(By.ID, "corePriceDisplay_desktop_feature_div")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading