我正在尝试创建一个工具来管理多个幻灯片共享帐户。手动登录和注销每个人都非常烦人,因此想到创建一个简单的网络浏览器工具来为我进行登录。
问题是,当我尝试点击登录按钮时,它告诉我“需要填充字段”(它们是),然后当我关注控件并尝试手动按下登录(从 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