完成网页自动登录了

Module Module1
    Sub WebLogin(ByVal web As System.Windows.Forms.WebBrowser, ByVal uname As System.Windows.Forms.TextBox, ByVal pass As System.Windows.Forms.TextBox)
        Dim htm As HtmlElementCollection = web.Document.getElementsByTagName_r("input") ‘是GetElementsByTagName ,网页显示不正确      

      Dim i As Int32
        If web.ReadyState = WebBrowserReadyState.Interactive Then
            Dim username As String = uname.Text
            Dim password As String = pass.Text
            Dim str As String = String.Empty
            For i = 0 To htm.Count - 1
                str = htm(i).Name
                If str = "username" Then
                    htm(i).SetAttribute("value", username)
                ElseIf str = "password" Then
                    htm(i).SetAttribute("value", password)
                End If
                If username <> String.Empty And password <> String.Empty And str = "submit" Then '如果用户名和密码不为空,html元素为登录按钮则点击登录
                    htm.Item(i).InvokeMember("click")  '点击Login 按钮登录
                End If
            Next
        End If
    End Sub
End Module

你可能感兴趣的:(VB.NET编程)