使用Selenium Webdriver,Python检索动态值

帕克塞尔

我知道已经存在与此类似的线程。但是,当尝试使用先前建议的方法来检索我的特定动态表值时,我得到的只是nbsp值或类似"1a207feb-8080-4ff0-..."

我正在尝试做的是:

此处获取当前欧元/盎司的黄金表价格我“检查”了页面并得到了xpath (//*[@id="bullionPriceTable"]/div/table/tbody/tr[3]/td[3]/span)

我的代码:

driver = webdriver.Chrome("path/to/chromedriver")
driver.get("https://www.bullionvault.com/gold-price-chart.do")

xpath = '//*[@id="bullionPriceTable"]/div/table/tbody/tr[3]/td[3]/span'

select=driver.find_element_by_xpath(xpath)
print(select)

打印:

<selenium.webdriver.remote.webelement.WebElement (session="3ade114e9f0907e4eb13deac6a264fc8", element="3a670af5-8594-4504-908a-a9bfcbac7342")>

显然不是我要找的电话号码。

我也尝试过在webElement上使用get_attribute('innerHtml')和.text,但无济于事。我在这里想念什么?我只是不正确地编码此值,还是我从错误的来源提取?

0立方米

等待页面加载,然后尝试获取innerHTML类似以下示例的内容

import time

from selenium import webdriver

chrome_browser = webdriver.Chrome(
    executable_path=r"chromedriver.exe")

chrome_browser.get("https://www.bullionvault.com/gold-price-chart.do")

time.sleep(2)

select = chrome_browser.find_element_by_xpath(
    "//*[@id='bullionPriceTable']/div/table/tbody/tr[3]/td[3]/span"
).get_attribute("innerHTML")

print(select)

€1,450.98

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章