vb模拟器webbrowser实战讲解之三
vb模拟器webbrowser实战讲解之三
这次我们要填表咯:
原理没有什么好说的了,基本都是上次的那些,如果不是很熟悉的话可以在程序里设置断点来观察个部分标签的结构和属性,下面就是代码了:
ElseIf InStr(1, .LocationURL, "http://members.sina.com.cn/ocgi/newform.cgi") <> 0 Then
For I = 0 To .Document.All.length - 1
Set mTag = .Document.All.Item(I)
Select Case mTag.tagname
Case "INPUT" '这里注意大写
Select Case mTag.Name
Case "login" '用户名
UserName = GetRndChar(Rnd * 2 + 1, 1) & GetRndChar(Rnd * 2 + 5, 2)
mTag.Value = UserName
Case "passwd" '密码
UserPassword = GetRndChar(Rnd * 2 + 6, 2)
mTag.Value = UserPassword
Case "pass2" '从新输入密码
mTag.Value = UserPassword
Case "question" '查询密码问题
mTag.Value = GetRndChar(Rnd * 3 + 3, 1)
Case "answer" '查询密码答案
mTag.Value = GetRndChar(Rnd * 4 + 6, 1)
Case "firstname" '真实姓名
mTag.Value = GetRndChar(Rnd * 4 + 6, 1)
Case "gender" '性别
'这里是radio
If mTag.Value = "Female" Then
mTag.Checked = True '不管什么,先选一个
Else
If (Rnd * 2) / 1 = 0 Then
mTag.Click '做个随机,男女平分
End If
End If
Case "BirthYear" '出生年
mTag.Value = 1910 + (GetRndChar(2, 0) Mod 80)
Case "BirthMonth" '出生月
mTag.Value = (GetRndChar(2, 0) Mod 12) + 1
Case "BirthDay" '出生日
mTag.Value = (GetRndChar(2, 0) Mod 28) + 1
Case "hobbies" '兴趣爱好
If Int(Rnd * 3) = 1 Then
mTag.Checked = True
End If
'这里是checkbox
Case "city" '添城市
mTag.Value = GetRndChar(Rnd * 2 + 4, 1)
Case "address" '添地址
mTag.Value = GetRndChar(Rnd * 2 + 4, 1)
Case "zip" '邮编
mTag.Value = "1" & GetRndChar(5, 0)
Case "phone" '电话
mTag.Value = GetRndChar(Rnd * 2 + 7, 0)
Case "idnumber" '证件号码
mTag.Value = GetRndChar(15, 0)
Case "Write" '提交
mTag.Click
Exit For
End Select
Case "A"
If mTag.href = "http://members.sina.com.cn/ocgi/newform.cgi#func1" Then
If mTag.innertext = "是的,我需要一个新的新浪免费邮箱。" Then mTag.Click
ElseIf mTag.href = "http://members.sina.com.cn/ocgi/newform.cgi#func3" Then
mTag.Click
End If
Case "SELECT"
Dim tSelect As Long
tSelect = Int(Rnd * (mTag.All.length - 1)) + 1
mTag.All.Item(tSelect).Selected = True
End Select
Next IElseIf .LocationURL = "http://members.sina.com.cn/ocgi/editnew.cgi" Then
If InStr(1, .Document.activeelement.outertext, "新浪网祝贺您注册成功!欢迎您成为新浪会员!") <> 0 Then
SaveUser
.Navigate "http://members.sina.com.cn/apply/"
Else
.GoBack
End IfEnd If
这次我们用到了一个函数GetRndChar,这个是我写的了,代码在下面:
Private Function GetRndChar(charLen As Integer, flag As Integer)
Dim mchar As String
Dim I As Integer
Dim tStr As String
Select Case flag
Case 0
'数字
mchar = "0123456789"
For I = 1 To charLen
tStr = tStr & Mid(mchar, Int(Rnd * 10) + 1, 1)
Next I
Case 1
'字母
mchar = "abcdefghijklmnopqrstuvwxyz"
For I = 1 To charLen
tStr = tStr & Mid(mchar, Int(Rnd * 26) + 1, 1)
Next I
Case 2
'混合
mchar = "abcdefghijklmnopqrstuvwxyz0123456789"
For I = 1 To charLen
tStr = tStr & Mid(mchar, Int(Rnd * 36) + 1, 1)
Next I
End Select
GetRndChar = tStr
Debug.Print tStrEnd Function
----------广告时间,请不要走开----------
如果你不知道什么是emailclear的话请注意了,这个软件是我写的一个工具,在我主页可以下载到
功能:清理信箱里的所有信件,完全删除。
具体情况请下载试用
---广告结束---
在最后我们注册成功了我们调用SaveUser过程来保存用户信息:
Private Sub SaveUser() Dim F As Integer Dim FileName As String F = FreeFile() FileName = App.Path & "\user.txt" Open FileName For Append As #F Print #F, UserName & ":" & UserPassword & "@pop3.sina.com.cn:110" '这里我们按emailclear的格式导出用户信息 Close #FEnd Sub
好咯~sinaMail至此全部结束,但是webbrowser得更深入的探讨我还会继续下去,请大家支持,由于本人水平有限,文章中不正确的地方还请各位高手指点