建立 InternetExplorer.Application COM 物件,導航至登入頁,等待載入完成,填寫表單欄位並送出。
On Error Resume Next
url = "https://www.bathome.net/logging.php?action=login"
username = "your_username"
password = "your_password"
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate url, 4
' 等待頁面載入 (readyState=4)
waittime = 0
Do Until 4 = ie.readyState
WScript.Sleep 200
waittime = waittime + 200
If waittime > 15000 Then Exit Do
Loop
If 4 <> ie.readyState Then
ie.Quit
WScript.Quit
End If
Set dom = ie.Document
Set form = dom.getElementById("loginform")
form.all("username").Value = username
form.all("password").Value = password
form.all("cookietime").Checked = True
form.all("loginsubmit").Click()
CreateObject("InternetExplorer.Application"):啟動 IE 實例 (需安裝 IE)。Visible = True:顯示視窗,方便除錯;正式可設 False 隱藏。Navigate url, 4:旗標 4 表示不讀取快取。readyState 等待完成,設定 15 秒逾時機制。ie.Document 取得 DOM,透過 getElementById / all 集合操作表單元素。Click() 觸發提交按鈕。WinHttp 或 Selenium。