【发布时间】:2020-06-02 18:41:53
【问题描述】:
<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 Web Inspector 中获取。我正在使用 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:消息:没有这样的元素:无法找到元素:{“method”:“css selector”,“selector”:“.ng-binding”} (会话信息:headless chrome=83.0.4103.61)
硒 3.141.0 Python 3.8
【问题讨论】:
-
欢迎来到 SOF!请添加您尝试过的代码n没有工作?
-
如果有错误也添加错误
-
我尝试了很多代码,但没有一个对我有用向我们展示你尝试了什么以及你得到的输出。
-
URL 需要时间才能完全加载。因此,您需要让驱动程序等到元素可见。一次,它会变得可见,然后您应该执行操作以废弃您想要的值。参考:stackoverflow.com/questions/26566799/…
-
非常感谢 Vishal 提供的信息
标签: python python-3.x selenium selenium-chromedriver