VB6里自動(dòng)提交/自動(dòng)填表的一種相對(duì)通用的方案
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
論壇里有人問(wèn)起,就看了一下,發(fā)現(xiàn)代碼比較簡(jiǎn)單.
而且這樣子應(yīng)該能比較通用地完成網(wǎng)頁(yè)自動(dòng)填表功能,適合做自動(dòng)提交之類的. 干脆記下來(lái),免得以后要用到時(shí)又忘了............... 代碼沒(méi)幾句,就是通過(guò)ID或NAME來(lái)取得對(duì)象,再設(shè)置其VALUE值. 論壇里的兩個(gè)帖子: http://www.m5home.com/bbs/dispbbs.asp?boardid=27&Id=2721 http://www.m5home.com/bbs/dispbbs.asp?boardid=27&Id=2754 使用的代碼都是同樣的一份: 復(fù)制內(nèi)容到剪貼板 程序代碼 Option Explicit Private Const sURL As String = "http://218.202.107.178:8081/aincs/webpage/index.jsp?SelfSessionKey=000000000000001a49444c3a687474702f52657150726f636573736f723a312e300000000000000100000000000000ac000102000000000c31302e3232302e332e313900ff8400000000004900504d43000000000000001a49444c3a687474702f52657150726f636573736f723a312e300020200000000974635f61696e6373002020200000000d2f746f6d636174345f706f6100000000000000035649530300000005000507017f000000000000000000000800000000564953000000000100000018000000000001000100000001050100010001010900000000_7A1B861487D6AFEDE237964589A17B26" Private Sub Form_Load() WebBrowser1.Navigate sURL End Sub Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) If URL = sURL Then Dim Ele As Object Set Ele = WebBrowser1.Document.getElementById("mobileno") '根據(jù)ID取得對(duì)象 Ele.Value = "www.m5home.com" Set Ele = WebBrowser1.Document.getElementsByName("password") '根據(jù)Name取得對(duì)象 Ele(0).Value = "www.m5home.com" Set Ele = WebBrowser1.Document.getElementsByName("operVerifyCode") '根據(jù)Name取得對(duì)象 Ele(0).Value = "www.m5home.com" End If End Sub 在使用getElementsByName取對(duì)象時(shí)要注意一點(diǎn),就是NAME是可以有重復(fù)的,所以getElementsByName返回的是一個(gè)集合,其中包含了所有相同NAME的對(duì)象. 而ID是不可能有重復(fù)的,所以getElementById返回的就是一個(gè)單一對(duì)象. 試過(guò)了pudn和CSDN等,都可以用這樣的方式自動(dòng)填表. 該文章在 2013/12/11 15:29:50 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |