-1

Hello i have a problem and searched for a little while in the internet, but most of the times the answers could not helped me.

I want to store/copy the latest price from a site (Webscraping, Kinguin)

Code:

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome('.\driver\chromedriver.exe')
driver.get("https://www.kinguin.net")

try:
    KingInput = driver.find_element_by_id('search')
    KingInput.send_keys('far cry 5')
    webdriver.ActionChains(driver).send_keys(Keys.ENTER).perform()


    # The Error happens here 
    Kprice = driver.find_element_by_class_name('price add-tax-rate relative-price-container').text()
    print(type(Kprice))
    print(Kprice)

    sleep(5)
    driver.close()    

except:
    print("Error")

I hope you can help me and I'm struggling for while.

Thanks in advance

JeffC
  • 22,180
  • 5
  • 32
  • 55
KaanDev
  • 49
  • 8
  • Can you post the error output? Or are you just getting your `except` "Error"? – Kang Mar 31 '18 at 20:56
  • Possible duplicate of [Python and how to get text from Selenium element WebElement object?](https://stackoverflow.com/questions/28022764/python-and-how-to-get-text-from-selenium-element-webelement-object) – JeffC Apr 01 '18 at 03:52

1 Answers1

0

If this is what you expected. Try this:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome() #define the path if nnecessary
driver.get("https://www.kinguin.net")

try:
    KingInput = driver.find_element_by_id('search')
    KingInput.send_keys('far cry 5',Keys.ENTER)

    Kprice = driver.find_element_by_css_selector('.actual-price span').text
    print(Kprice)

finally:
    driver.close()
SIM
  • 21,997
  • 5
  • 37
  • 109
  • ty mate that helped me alot – KaanDev Mar 31 '18 at 21:02
  • If it solves the issue, don't forget to tick the grayed out checkmark between the up/down buttons next to my answer to select it as the accepted solution. – SIM Mar 31 '18 at 21:04