<div class="flexible row ng-scope">
<!-- ngRepeat: graph in graphs track by $index --><figure class="figure-gauge flexible column ng-scope" data-ng-repeat="graph in graphs track by $index">
<figcaption class="rigid">
<div class="data-value">
<b class="ng-binding">
334
</b>
</div>
我需要提取出现的值(334(,我从Chrome网页检查器中获取此值。我正在使用python和selenium,我尝试过许多代码,但没有一个对我有用,我感谢任何帮助。
我试试这个:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
DRIVER_PATH = r'C:chromedriver.exe'
options = Options()
options.headless = True
options.add_argument("--window-size=1920,1200")
driver = webdriver.Chrome(options=options, executable_path=DRIVER_PATH)
driver.get("https://iot.app.initialstate.com/embed/#/tiles/bkt_kb448kawjvmhe")
data = driver.find_element_by_class_name('ng-binding')
print
driver.quit()
错误: selenium.common.exceptions.NoSuchElementException: 消息: no suchElement: 无法定位元素: {"method":"css selector","selector":".ng-binding"} (会话信息:无头铬=83.0.4103.61(
硒 3.141.0 蟒蛇 3.8
您需要提供一些sleep()
来加载图形上的值,然后使用下面的xpath
来获取值。
driver.get("https://iot.app.initialstate.com/embed/#/tiles/bkt_kb448kawjvmhe")
time.sleep(3)
print(driver.find_element_by_xpath("(//div[@class='data-value']/b)[last()]").text.strip())
您可以使用xpath 提取它
val = driver.find_element_by_xpath('/html/body/div[1]/article/div[2]/div/div/div[1]/article/div/figure/figcaption/div/b').text
print(val)