我正在尝试Rueters.com
通过我的 VB.net 程序登录。到目前为止,我的代码一直有效,直到我单击“登录”按钮。没有发生错误,但它也没有登录。我究竟做错了什么?提前感谢您的帮助。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("https://commerce.us.reuters.com/login/pages/login/login.do?backUrl=http%3A%2F%2Fwww.reuters.com%2F&backParameterEncoded=false&source=portfolio&flow=PORTFOLIO&entry_source=registration")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.Document.GetElementById("loginName").SetAttribute("value", "username")
WebBrowser1.Document.GetElementById("password").SetAttribute("value", "password")
Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
For Each webpageelement As HtmlElement In allelements
If webpageelement.GetAttribute("class") = "button" Then
webpageelement.InvokeMember("click")
End If
Next
End Sub
抱歉,我忘了包含 HTML!这里是:
<div class="label">
Email</div>
<div class="textfield">
<input type="text" size="40" maxlength="100" name="loginName" value="username" />
</div>
<div class="label">
Password</div>
<div class="textfield">
<input type="password" value="" size="40" maxlength="20" name="password" />
</div>
<div class="checkbox">
<input type="hidden" value="true" name="flag" />
<input type="checkbox" onclick="if(this.checked) this.form.flag.value='true'; else this.form.flag.value='false';" id="RememberCredentialsCBID" checked="checked" />
<label class="label" for="RememberCredentialsCBID">Remember me on this computer</label>
</div>
<div id="loginErr" class="label error">
</div>
<div class="submit">
<div class="button"><input type="image" src="/resources_v2/images/btn_sign_in.gif" />
</div>
</div>
<div class="textfield">
<a href="/login/restorePassword">Forgot your password?</a>
</div>
</form>