0

我正在尝试创建一个工具来管理多个幻灯片共享帐户。手动登录和注销每个人都非常烦人,因此想到创建一个简单的网络浏览器工具来为我进行登录。

问题是,当我尝试点击登录按钮时,它告诉我“需要填充字段”(它们是),然后当我关注控件并尝试手动按下登录(从 webbrowser 控件中)时,我告诉我这是“无效的用户名/密码组合”

我什至更进一步,从输入中删除了文本,并从文本文件中重新粘贴了相同的文本,但出现了相同的“无效用户/通行证”消息。

当我尝试从实际的 IE 浏览器手动执行此操作时,它登录没有问题。我不知道我做错了什么。这是代码:

Private Sub targetSlideshare()
    Dim details() As String
    details = accounts(currentAcc).Split(":")
    user = details(0)
    pass = details(1)
    Label19.Text = (currentAcc + 1).ToString + "/" + accounts.Length.ToString

    status = "Logout"
    Label20.Text = status
    loaded2 = False
    WebBrowser2.Navigate("https://www.slideshare.net/logout")
    While loaded2 = False
        Threading.Thread.Sleep(1000)
    End While
    Threading.Thread.Sleep(1000)

    status = "Logging In"
    Label20.Text = status
    loaded2 = False
    WebBrowser2.Navigate("https://www.slideshare.net/login")
    While loaded2 = False
        Threading.Thread.Sleep(1000)
    End While
    Threading.Thread.Sleep(5000)
End Sub

Private Sub WebBrowser2_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser2.DocumentCompleted
    If WebBrowser2.ReadyState <> WebBrowserReadyState.Complete Then
        Exit Sub
    End If
    If status = "Logout" Then
        loaded2 = True
    ElseIf status = "Logging In" Then
        WebBrowser2.Document.GetElementById("user_login").SetAttribute("value", user)
        'WebBrowser2.Document.GetElementById("user_login").SetAttribute("placeholder", Nothing)
        WebBrowser2.Document.GetElementById("user_password").SetAttribute("value", pass)
        'WebBrowser2.Document.GetElementById("user_password").SetAttribute("placeholder", Nothing)
        Dim allelements As HtmlElementCollection = WebBrowser2.Document.All
        For Each webpageelement As HtmlElement In allelements
            If webpageelement.GetAttribute("value") = "Login" Then
                status = "Loading"
                webpageelement.InvokeMember("click")
            End If
        Next

        loaded2 = True
End Sub
4

1 回答 1

0

我无法从我当前所在的 PC 访问该站点,但以下操作对我登录 Google 有用:

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    WebBrowser1.Navigate("https://accounts.google.com/ServiceLogin?hl=en&continue=https://www.google.com/")
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    WebBrowser1.Document.GetElementById("Email").InnerText = user.ToString
    WebBrowser1.Document.GetElementById("Passwd").InnerText = pass.ToString
    WebBrowser1.Document.GetElementById("signIn").InvokeMember("click")
End Sub

另一个可能有用的技巧:

我发现当我在通过某些桌面网站上的网络浏览器控件登录时遇到问题时,尝试在移动版本上自动登录,即:https ://www.slideshare.net/mobile/login有时有效。

于 2013-05-21T14:11:19.323 回答