【发布时间】:2021-05-18 21:30:23
【问题描述】:
我正在尝试使用 python、selenium 和 xpath 来获取以下 HTML 块中的文本 $0.180,
<div class="wlp-values-div">
<span class="wlp-last-price-span">$0.180</span>
这段代码深入到网站的 HTML 中,我尝试使用以下 Xpath 来定位它:
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get("https://smallcaps.com.au/stocks/?symbol=AWJ")
time.sleep(3)
webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
ele = driver.find_element_by_xpath("//div[@class='wlp-values-div']/span[@class='wlp-last-price-span']")
但我收到错误:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class='wlp-values-div']/span[@class='wlp-last-price-span']"}
任何帮助将不胜感激
【问题讨论】:
-
可能问题是元素在框架中。
-
我没有,我不知道该怎么做并用 xpath 格式化它
标签: python selenium-webdriver xpath iframe css-selectors