iT邦幫忙

1

python 監聽輸入

大家好,目前自己在研究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)
看更多先前的討論...收起先前的討論...
哇,好邪惡的感覺.....建議你朝向self proxy 的方向去想,祝你找到好方法
打雜工 iT邦研究生 1 級 ‧ 2021-01-29 09:41:24 檢舉
爬別人的網頁,監聽第三人的輸入內容!(還是我誤會樓主的意思了)
蠻酷的,可以做到? 我想學~
我相信樓主只是想把這個監聽當成是破解客戶端跟伺服器之間的資料是怎麼加密的......

從硬體下手,好過你自己做這些擦邊球
player iT邦大師 1 級 ‧ 2021-01-30 18:24:08 檢舉
你只能抓到本機端的 (如果要抓別台的, 那叫封包監聽)
HTML的DOM有一堆事件
你要去接改變的事件吧
這樣才能抓到 TextBox被改變過的內容
事件觸發的寫法
自己google找吧
qpalzm iT邦新手 1 級 ‧ 2021-02-01 09:02:59 檢舉
謝謝各位~回答,假日在忙所以沒回到~我的想法是python有辦法做到像javascript addlistener 或是 jq .on 這種的監聽 不是~監聽地3人的內容~這太恐怖了~只是想從DOM 去處發事件 只是PYTHON 找不到這類的方法 所以才想來問問看~
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
coreyqaq
iT邦新手 5 級 ‧ 2021-02-15 10:43:47
最佳解答

請問樓主是否想做的是這種效果?
https://ithelp.ithome.com.tw/upload/images/20210215/201351526cmImw7P1N.png

如果是的話 這是我的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)


qpalzm iT邦新手 1 級 ‧ 2021-02-16 19:36:44 檢舉

是的!!!!! 謝謝你!!!

我要發表回答

立即登入回答