VB实现自动填表15616
来源:百度文库 编辑:神马文学网 时间:2024/04/29 11:09:26
转:
怎么编程把用户名,密码提交到网页上的登录页?
首先在程序中加入Webbrowser控件并加入引用 Microsoft HTML Object Library。
假设你的HTML页面表单代码如下:
注意其中元素的type、Name、value属性。然后VB中的代码如下:
Private Sub Command1_Click()
WebBrowser1.Navigate "http://chen/chat/newuser.htm"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim vDoc, vTag
Dim i As Integer
Set vDoc = WebBrowser1.Document
List1.Clear
For i = 0 To vDoc.All.length - 1
If UCase(vDoc.All(i).tagName) = "INPUT" Then
Set vTag = vDoc.All(i)
If vTag.Type = "text" Or vTag.Type = "password" Then
List1.AddItem vTag.Name
Select Case vTag.Name
Case "Name"
vTag.Value = "IMGod"
Case "NickName"
vTag.Value = "IMGod"
Case "Password"
vTag.Value = "IMGodpass"
Case "EMail"
vTag.Value = "IMGod@paradise.com"
End Select
ElseIf vTag.Type = "submit" Then
vTag.Click
End If
End If
Next i
End Sub
点击Command1就可以自动填表并提交了。
for i=0 to webbrowser1.document.frames.length
'操作webBrowser1.document.frames(i).document
next
操作这个webBrowser1.document.frames(i).document操作WebBrowser1.Document完全一样,
webbrowser1.document.frames.length为本页内框架数量
PS:本功能仅限填写非跨域网页,对于跨域框架网页没找到什么好办法,我只会一个比较笨的办法。
webBrowser1.document.frames(2).frames(1).document可以定位到桢2的Document里面去。
无论多少层、多少桢,理论上都可以这样定位的---跨区域除外,不过一般跨区域的不多。
==================
网页=(帧1+帧2+帧3+帧4)
变成了
网页=[帧1+帧2+帧3(帧1+帧2)+帧4],即帧内又套用帧了。我要填写的部分在“帧3(帧1+帧2)”的帧2里。