你好,我有一个问题并在互联网上搜索了一会儿,但大多数时候答案都无法帮助我。
我想存储/复制网站的最新价格(Webscraping,Kinguin)
代码:
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")
我希望你能帮助我,我一直在挣扎。
提前致谢
答案 0 :(得分:0)
如果这是你所期望的。试试这个:
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()