[英]How to create a new line when only using \n with variables rather than printed text?
[英]Text is not printed when using selenium
这是我到目前为止写的代码:
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
chrome_driver_path = "C:\Development\chromedriver.exe"
driver = webdriver.Chrome(executable_path=chrome_driver_path)
driver.get("https://www.amazon.ae/Kingston-SA400S37-480G-480GB-A400/dp/B01N6JQS8C/ref=lp_12050241031_1_12?th=1")
price = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[7]/div[3]/div[4]/div[11]/div[1]/div/table/tbody/tr[2]/td[2]/span[1]/span[1]').text
print(price)
#driver.close()
driver.quit()
价格的值是空白的。
您应该在xpath
拖尾span[1]
替换为span[2]
这是代码 -
from selenium import webdriver
chrome_driver_path = "drivers\\chromedriver.exe"
driver = webdriver.Chrome(executable_path=chrome_driver_path)
driver.get("https://www.amazon.ae/Kingston-SA400S37-480G-480GB-A400/dp/B01N6JQS8C/ref=lp_12050241031_1_12?th=1")
price = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[7]/div[3]/div[4]/div[11]/div[1]/div/table/tbody/tr[2]/td[2]/span[1]/span[2]').text
print("price: ", price)
driver.close()
driver.quit()
Output -
price: AED81.64
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.