Public Sub WriteToForm(ByVal Obj As Object, ByVal sTagName As String, ByVal sName As String, ByVal Submit As Boolean, Optional sType As String = "", Optional sValue As String = "", Optional sSelect As Boolean)
Dim i As Integer
Dim vDoc, vTag
sTagName = UCase(sTagName)
sType = UCase(sType)
sName = UCase(sName)
Set vDoc = Obj.Document
For i = 0 To vDoc.All.Length - 1
If UCase(vDoc.All(i).tagname) = sTagName Then
Set vTag = vDoc.All(i)
If sTagName = "SELECT" Or sTagName = "TEXTAREA" Then
If UCase(vTag.Name) = sName Then vTag.Value = sValue
Else
If sType = "RADIO" Or sType = "CHECKBOX" Then
sValue = UCase(sValue)
If UCase(vTag.Name) = sName And UCase(vTag.Value) = sValue Then
If sSelect Then
vTag.Checked = True
Else
vTag.Checked = False
End If
End If
Else
If Submit Then
If UCase(vTag.Type) = sType And UCase(vTag.Name) = sName Then vTag.Click
Else
If UCase(vTag.Type) = sType And UCase(vTag.Name) = sName Then vTag.Value = sValue
End If
End If
End If
End If
Next i
'应用举例=================================================
End Sub
Private Sub Command1_Click()
WriteToForm WebBrowser1, "input", "imembernamelive", False, "text", "文本框" '输入文本
'WriteToForm WebBrowser1, "input", "checkbox3", False, "checkbox", "3", True '复选框打钩
'WriteToForm WebBrowser1, "input", "checkbox5", False, "checkbox", "5", False '复选框不打钩
WriteToForm WebBrowser1, "input", "iPwd", False, "password", "123456" '密码框
WriteToForm WebBrowser1, "select", "iBirthYear", False, "select", "1654" '列表框
WriteToForm WebBrowser1, "input", "profile_gender", False, "radio", "f", True '单选框
WriteToForm WebBrowser1, "input", "submit", True, "submit" '提交按钮
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "https://signup.live.com/signup.aspx?ru=http%3a%2f%2fmail.live.com%2f%3frru%3dinbox&wa=wsignin1.0&rpsnv=11&ct=1264506837&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fsn109w.snt109.mail.live.com%2Fdefault.aspx&lc=2052&id=64855&mkt=zh-cn&bk=1264506838&rollrs=12&lic=1"
End Sub
来自于:http://blog.sina.com.cn/s/blog_51daddff01009ckc.html
2
1、新建工程
2、加入控件WebBrowser1和按钮command1
3、在command1的click事件中加入如下代码
Private Sub Command1_Click()
Dim vDoc, vTag
Dim i As Integer
Set vDoc = webBrowser1.Document
For i = 0 To vDoc.All.length - 1 '检测所有标签
If UCase(vDoc.All(i).tagName) = "INPUT" Then '找到input标签
Set vTag = vDoc.All(i)
If vTag.Type = "text" Then '看看是不是我们需要的
Select Case vTag.Name
Case "subject" '写标题,不同的网页表单,vTag.name的值不同,要查看网页源码
并根据实际更改。下同。
vTag.Value = "你的文章标题"
End Select
If vTag.Type = "textarea" Then '写发言内容,textarea表示文本区域
Select Case vTag.Name
Case "body" 'body是文本区域的name,从网页源码中查知。
vTag.Value = "你的文章内容"
End Select
If vTag.Type = "submit" And vTag.Value = "发表" Then '找到发表按钮。
vTag.Select '也可以没有这个
vTag.Click '点击提交了,一切都OK了
End If
End If
End If
End If
Next i
End Sub
在form1的load事件中是如下代码:
Private Sub Form_Load()
WebBrowser1.Navigate "http://goal28.ziqu.com/fcgi-bin/addboard.f...bookname=250006" '软件一启
动就导航到这个地址
End Sub
运行软件,点击command1,即自动填表并提交。
问题是:vb可以自动填写文章标题,并提交。但不能填写文本区域发言内容。估计问题出在这个代码
vTag.Value="你的文章内容"
这句代码应该怎么写,才能让vb自动填写发言内容?或者vTag后面应是什么属性?
请问高手怎么样才能将填写好的内容发表到textarea文本区域中呢
以上代码是不是有误,
我想这里 If UCase(vDoc.All(i).tagName) = "INPUT" Then '找到input标签 有问题还有:
If vTag.Type = "textarea" Then '写发言内容,textarea表示文本区域
Select Case vTag.Name
Case "body" 'body是文本区域的name,从网页源码中查知。
vTag.Value = "你的文章内容"
End Select
来自于:http://www.vbgood.com/thread-40194-1-1.html
http://www.itc8.cn/a/bianchengleyuan/2011/0126/202.html
Private Sub Form_Load()
WebBrowser1.Navigate "http://www.126.com"
End Sub
Private Sub WebBrowser1_DownloadComplete()
Dim vDoc, vTag
Dim i As Integer
Set vDoc = WebBrowser1.Document
For i = 0 To vDoc.All.length - 1 '检测所有标签
If UCase(vDoc.All(i).tagName) = "INPUT" Then '找到input标签
Set vTag = vDoc.All(i)
If vTag.Type = "text" Then '检测类型
Select Case vTag.Name
Case "user" '填写用户名的文本框的值
vTag.Value = "aaa"
End Select
End If
If vTag.Type = "password" Then '检测密码框类型
Select Case vTag.Name
Case "pass" '密码框的值
vTag.Value = "12"
End Select
End If
If vTag.Type = "submit" And vTag.Value = "登录邮箱" Then '登陆按钮
vTag.Click
End If
End If
Next i
End Sub