VB中用webbrowser如何提交数据
请问webbrowser如何提交数据,不是input控件。如何click?<A id=publisher_submit title=发布微博 tabIndex=8 href="javascript:void(0);">
答案:首先在程序中加入Webbrowser控件并加入引用 Microsoft HTML Object Library。
假设你的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就可以自动填表并提交了。
这是参考地址 http://topic.csdn.net/t/20020621/16/821289.html
上一个:在VB中的Timer控件怎么用?
下一个:VB内部函数,Val怎么用呀?