来源:网络 | 2007-2-9 | (有8179人读过)
主题:用户名,密码提交到网页上的登录页:
首先在程序中加入Webbrowser控件
假设你的HTML页面表单代码如下:
<form method="POST" action="http://chen/dll/chat/chatmain.exe/RegUser">
<p>请填写下面表单注册(*项为必添项)</p>
<p>*姓名<input type="text" name="Name" size="20"></p>
<p>*昵称<input type="text" name="NickName" size="20"></p>
<p>电子邮件<input type="text" name="EMail" size="20"></p>
<p>*密码<input type="text" name="Password" size="20"></p>
<p><input type="submit" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"></p>
</form>
注意其中元素的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就可以自动填表并提交。
|