积极答复者
VB2010怎么实现自动填表啊

问题
答案
-
你好,我这有个自动登录的例子,你可以试试:
Private Sub AutoLogin_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Me.WebBrowser1.Navigate("E:\Projects\WinApp-webbrowser\WinApp-webbrowser\Loginform.htm") 'Me.WebBrowser1.Navigate("www.google.com.hk") End Sub 'Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted ' Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input") ' For Each curElement As HtmlElement In theElementCollection ' Dim controlName As String = curElement.GetAttribute("id").ToString ' If controlName = "usernameLogin" Then ' curElement.SetAttribute("Value", "username") ' ElseIf controlName = "passwordLogin" Then ' curElement.SetAttribute("Value", "password") ' End If ' Next 'End Sub Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("form") For Each curElement As HtmlElement In theElementCollection If curElement.GetAttribute("action") = "http:\\www.google.com.hk" Then curElement.InvokeMember("submit") Next End If End Sub
这段代码中的注释部分也很有参考价值的,别忽略了。
另外你需要做些调整,然后才能跟你自己原本的程序融合。
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike FengModerator 2011年12月26日 17:11
全部回复
-
你好,我这有个自动登录的例子,你可以试试:
Private Sub AutoLogin_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Me.WebBrowser1.Navigate("E:\Projects\WinApp-webbrowser\WinApp-webbrowser\Loginform.htm") 'Me.WebBrowser1.Navigate("www.google.com.hk") End Sub 'Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted ' Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input") ' For Each curElement As HtmlElement In theElementCollection ' Dim controlName As String = curElement.GetAttribute("id").ToString ' If controlName = "usernameLogin" Then ' curElement.SetAttribute("Value", "username") ' ElseIf controlName = "passwordLogin" Then ' curElement.SetAttribute("Value", "password") ' End If ' Next 'End Sub Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("form") For Each curElement As HtmlElement In theElementCollection If curElement.GetAttribute("action") = "http:\\www.google.com.hk" Then curElement.InvokeMember("submit") Next End If End Sub
这段代码中的注释部分也很有参考价值的,别忽略了。
另外你需要做些调整,然后才能跟你自己原本的程序融合。
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike FengModerator 2011年12月26日 17:11