1
我想通過我的VB.net程序登錄到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>
它說,出現 「UnauthorizedAccessException是未處理」, 「訪問被拒絕。(從HRESULT異常:0X80070005(E_ACCESSDENIED))」 – gromit1
一旦WebBrowser1開始負載我得到一個安全警告。它說:「您是否想僅查看安全傳送的網頁內容?此網頁包含的內容不會使用安全的HTTPS連接傳送,這可能會危及整個網頁的安全。」如果我點擊否,那麼我得到上面顯示的UnauthorizedAccessException錯誤。如果我點擊是,那麼我可以成功登錄。如何通過編程方式單擊yes按鈕,以便我不必每次都手動執行此操作? – gromit1
在Webbrowser1屬性中,將ScriptErrorsSuppressed更改爲True – Sparers