-1

Is it possible to extract the time from the site: https://w2.leisurelink.lcsd.gov.hk/index/index.jsp

I am using selenium, and seems like the time is generated from a javascript, so extracting the text for the element wouldn't work.

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
hbae
  • 91
  • 7
  • `js_time= driver.find_element_by_xpath("//form[@name='theClock']") val = driver.execute_script("arguments[0].value;", js_time) print(val)` .. just run this, you may have to change the xpath as I am not certain which node you really want to locate. – cruisepandey Dec 12 '21 at 12:46

1 Answers1

0

To extract the time you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get("https://w2.leisurelink.lcsd.gov.hk/index/index.jsp")
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[name='theTime']"))).get_attribute("value"))
    
  • Using XPATH:

    driver.get("https://w2.leisurelink.lcsd.gov.hk/index/index.jsp")
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@name='theTime']"))).get_attribute("value"))
    
  • Console Output:

    12-12-2021 20:45:15
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352