Previous questions are not solving this issue. It's 2022, questions from 2015 aren't helping. I've read previous TypeError:'str' questions on stack overflow and, believe it or not, they're not helping.
What I am trying to do is use find_element() to get the price($199.99) of this 21 in 1 pressure cooker and then display it with the print function. However, I get this error when I run my code:
line 10, in <module> price = driver.find_element(By.CLASS_NAME('a-price aok-align-center reinventPricePriceToPayMargin priceToPay')) TypeError: 'str' object is not callable
This is my code:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
service = Service("/Users/myname/Development/chromedriver")
driver = webdriver.Chrome(service=service)
driver.get("https://www.amazon.com/Instant-Pot-Electric-Pressure-One-Touch/dp/B08CF8J3M8/ref=sr_1_10?crid=3HDJU6IJ0LN6Y&keywords=instant+pot+9+in+1+electric+pressure+cooker&qid=1656866250&sprefix=instant+pot+9+in+1+electric+pressure+cooker%2Caps%2C98&sr=8-10")
price = driver.find_element(By.CLASS_NAME('a-price aok-align-center reinventPricePriceToPayMargin priceToPay'))
print(price.text)
driver.quit()
On this webpage, the price for this pressure cooker is displayed twice and I am trying to use the price displayed first (going from left to right) because when I right click and use inspect, the class name is unique, 1 of 1.
I have tried: find_element(by=By.CLASS_NAME, value=etc)
That didn't work.
This is a picture of the page from the above link. You can see the price to the pressure cooker is listed twice. I am trying to access the price on the left via the code from inspect (an option when you right click).
Here you can see the span class is: "a-price aok-align-center reinventPricePriceToPayMargin priceToPay". This is the left price.
Here you can see that the span class is shorter than aforementioned one, it's also common throughout this code
TL:DR, I'm trying to use find_element() to get the price of this item and then display it using print()


