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