用VB制作网站登陆器

Private Sub Command1_Click()
Wb1.Navigate "http://warlord.duowan.com/f1.html"
'连接到网站
End Sub

Private Sub WB1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim vDoc, vTag
Dim i As Integer
Set vDoc = Wb1.Document
List1.Clear
For i = 0 To vDoc.All.length - 1
If UCase(vDoc.All(i).tagName) = "INPUT" Then ' 查找Object属性为Input的可输入项
Set vTag = vDoc.All(i)
List1.AddItem vDoc.All(i).tagName
If vTag.Type = "text" Or vTag.Type = "password" Then
Select Case vTag.Name
Case "username" '如果是用户名的那个框
vTag.Value = "xxxxxxx" '这个是用户名
Case "passwd"
vTag.Value = "xxxxxxxxx" '这个是密码
Case "sessioncode"
vTag.Value = "xxxx" '这个是验证码
End Select
   With vDoc.All(i)
        If UCase$(.tagName) = "INPUT" Then ' 查找Object属性为Input的可输入项
          '如是,则判断其是否是制定图片链接,并可点击
          If UCase$(.Type) = "IMAGE" And .src     = "http://warlord.duowan.com/f1.html#" Then
             .Select '模拟选择图片
             .Click   '模拟鼠标单击
          End If
        End If
      End With
End If
End If
Next i
End Sub

这是我在网上找的,经过整理,验证过。
我现在也在做这方面事。
现阶段在最难得就是验证码!

URL

帐号

密码

其它参数

SOHU邮箱

http://login.sohu.com/chkpwd.php

UserName

Password

网易通行证

http://reg4.163.com/CheckUser.jsp

username

password

CSDN通行证

http://www.csdn.net/member/logon.asp

login_name

password

cookietime=0&

x=42&y=10

表格中的参数就是按照前面介绍的方法得到的,在程序中将要用到。

先说明一点, WebBrowser也是可以直接POST数据给Web服务器的,我将在第四部分给出代码。这里先看看InetWebBrowser相互配合的效果。

新建一个工程,部件中勾选中“Microsoft Internet Transfer Controls 6.0”、“Microsoft Internet Controls”,依次添加Inet1WebBrowser1Text1Text2Combo1在窗体上,可以把WebBrowser1适当拉大一点,将各控件位置安排好(可以参考运行后的图片),下面是代码:

    Dim URL1(2) As String: Dim URL2(2) As String

    Dim C1(2) As String: Dim C2(2) As String: Dim C3(2) As String

Private Sub Form_Load()

       Text1.Text = ""

    Text2.Text = ""

    Text2.PasswordChar = "*"

   Combo1.AddItem "SOHU邮箱", 0

    Combo1.AddItem "网易通行证", 1

    Combo1.AddItem "CSDN通行证", 2

    Combo1.AddItem "请选择一个登陆", 3

    Combo1.Text = Combo1.List(3)

    URL1(0) = "http://login.sohu.com/chkpwd.php": URL2(0) = "http://www34.mail.sohu.com/control/entry"

    URL1(1) = "http://reg4.163.com/CheckUser.jsp": URL2(1) = "http://reg4.163.com/Main.jsp?"

    URL1(2) = "http://www.csdn.net/member/logon.asp": URL2(2) = "http://www.csdn.net/Member/Passport.asp"

    C1(0) = "UserName": C2(0) = "Password": C3(0) = ""

    C1(1) = "username": C2(1) = "password": C3(1) = ""

    C1(2) = "login_name": C2(2) = "password": C3(2) = "cookietime=0&x=42&y=10"

End Sub

Private Sub Form_Resize()

If Me.WindowState <> 1 Then

    WebBrowser1.Left = 10

    WebBrowser1.Width = Me.Width - 120

    WebBrowser1.Height = Me.Height - 800

End If

End Sub

Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)

    If KeyCode <> 13 Then Exit Sub

    If Combo1.ListIndex = 3 Then MsgBox "请选择一个登陆": Exit Sub

    If Text1.Text = "" Then MsgBox "请输入用户名": Exit Sub

    If Text2.Text = "" Then MsgBox "请输入密码": Exit Sub

    Dim strFormData As String

    strFormData = C1(Combo1.ListIndex) + "=" + Text1.Text + "&" + C2(Combo1.ListIndex) + "=" + Text2.Text + "&" + C3(Combo1.ListIndex)

    Inet1.Execute URL1(Combo1.ListIndex), "Post", strFormData, "Content-Type: application/x-www-form-urlencoded "

    Do Until Inet1.StillExecuting = False '这里阻塞前面的Inet1,确保登陆成功之后再取页面,你可以将此Do取消了试一次。

        DoEvents

    Loop

    If Combo1.ListIndex = 1 Then

        WebBrowser1.Navigate URL2(Combo1.ListIndex) + C1(Combo1.ListIndex) + "=" + Text1.Text

    Else

        WebBrowser1.Navigate URL2(Combo1.ListIndex)

    End If

End Sub

你可能感兴趣的:(jsp,asp.net,asp,vb,VB.NET)