0
<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>

I need to extract the value (334) that appears, i take this from Chrome Web Inspector . I am using python and selenium, I have tried with many codes but none has worked for me, I appreciate any help.

I try whit this:

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()

Error: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".ng-binding"} (Session info: headless chrome=83.0.4103.61)

Selenium 3.141.0 Python 3.8

GB3
  • 11
  • 3
  • Welcome to SOF ! Please add what code have you tried n did not work ? – Sowjanya R Bhat Jun 02 '20 at 18:44
  • also add errors if any – Sowjanya R Bhat Jun 02 '20 at 18:44
  • _I have tried with many codes but none has worked for me_ Show us what you tried and the output you got. – John Gordon Jun 02 '20 at 18:50
  • The URL is taking time to get loaded completely. So, you need to let the driver wait until the element get visible. Once, it will get visible then you should perform the action to scrap the value you want. Reference: https://stackoverflow.com/questions/26566799/wait-until-page-is-loaded-with-selenium-webdriver-for-python – Vishal Kumar Jun 02 '20 at 20:39
  • thank you very much Vishal for the information – GB3 Jun 02 '20 at 20:56

2 Answers2

0

You can extract it using 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)
sleep
  • 104
  • 1
  • 1
  • 8
  • Later I tried your solution too, at first it didn't work, after adding the "time.sleep" as in the other answer, it worked fine, but it takes the value of the first inidicator, which is 100 and not the value 334, anyway thanks for your time and answer. – GB3 Jun 02 '20 at 20:45
0

You need to provide some sleep() to load the value on the graph and then use below xpath to get the value.

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())
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • It works, thank you very much, just as a small question. Will I always have to wait that long? – GB3 Jun 02 '20 at 20:37
  • Not always in this case since graph is taking time to load the value you had to provide some sleep. – KunduK Jun 02 '20 at 21:05