大家好,目前自己在研究python ,想請問我爬到一個網頁後可以透過監聽去監控一個html的input輸入欄位嗎?? 我做了每5秒印出欄位值可是都只能印出程式預設的值,無法監聽改變後的值。
import threading
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--disable-notifications")
chrome = webdriver.Chrome('./chromedriver', chrome_options=options)
chrome.get("https://www.facebook.com/")
email = chrome.find_element_by_id("email")
password = chrome.find_element_by_id("pass")
email.send_keys('xxxxxx@gmail.com.tw')
password.send_keys('xxxxxxx')
def setInterval(val, Time):
e = threading.Event()
while not e.wait(Time):
print('input:' + val)
setInterval(email.get_attribute('value'), 5)
請問樓主是否想做的是這種效果?
如果是的話 這是我的code:
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--disable-notifications")
chrome = webdriver.Chrome('./chromedriver.exe', chrome_options=options)
chrome.get("https://www.facebook.com/")
email = chrome.find_element_by_id("email")
password = chrome.find_element_by_id("pass")
email.send_keys('xxxxxx@gmail.com.tw')
password.send_keys('xxxxxxx')
while True:
val=chrome.find_element_by_id("email")
print(str(val.get_attribute('value')))
time.sleep(5)