1. 程式人生 > >後臺自動登入網頁vb指令碼例項程式碼

後臺自動登入網頁vb指令碼例項程式碼

set IE=createobject("Internetexplorer.application")
IE.Visible = True
IE.Navigate "https://www.xxx.com/login.htm"

‘等待網頁載入完成
While IE.busy Or IE.readystate<>4
Wend

'從網頁元素中找到設定的元素,並賦值
'因為form沒有name或id,只能從document的collection裡取forms集合
'再從中定位輸入框和提交按鈕
IE.Document.Forms(0).elements("name").value = "aaaa"
IE.Document.Forms(0).elements("passwd").value = "1111" 
IE.Document.Forms(0).elements("Send").click

'登入後介面是框架結構,先等主框架載入完成
While IE.busy Or IE.readystate<>4
Wend

'等框架內網頁1載入完成
While IE.busy Or IE.Document.Frames(1).document.readystate<>"complete"
Wend


'點選一個圖片按鈕/連結,需要先定位到框架內,再從document的collection裡取images集合
IE.Document.Frames(1).document.images(3).click

'等主框架載入完成

While IE.busy Or IE.readystate<>4

Wend

'等框架內網頁2載入完成
While IE.busy Or IE.Document.Frames(2).document.readystate<>"complete"
Wend

'定位select控制元件,並作出選擇
IE.Document.Frames(2).document.Forms(0).elements("lst_ed_day").selectedIndex=8
IE.Document.Frames(2).document.Forms(0).elements("lst_st_time").selectedIndex=1

'其他操作。。。。

=======================================================

html元素屬性可以參閱http://msdn.microsoft.com/en-us/library/ms533050(vs.85).aspx

InternetExplorer Object可參閱:http://msdn.microsoft.com/en-us/library/aa752084(VS.85).aspx