|
-
Mar 26th, 2007, 08:01 PM
#1
Thread Starter
New Member
[RESOLVED] [2005] Webbrowser - Waiting for form to load
Greetings
I'm trying to create a VB application that will login to a website and dump the HTML source to a local text file once logged in. I'm using the webbrowser object for this problem because the HTMLRequest object is not recognized as a supported browser when attempting to grab the initial login page. The website simply redirects me to a unsupported browser page. Below is my code:
Code:
Option Strict Off
Option Explicit On
Imports System.Net
Imports System.IO
Imports System.Threading
Friend Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
wWeb.Navigate("http://www.website.com")
MessageBox.Show("page loaded")
End Sub
Private Sub butLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butLogin.Click
wWeb.Document.All.Item("email").InnerText = "user@domain"
wWeb.Document.All.Item("pass").InnerText = "xxxxx"
wWeb.Document.All.Item("doquicklogin").InvokeMember("click")
End Sub
Private Sub butExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butExit.Click
Application.Exit()
End Sub
Private Sub butdump_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butdump.Click
'Dim html As String = wWeb.Document.Body.InnerHtml
Dim html As String = wWeb.DocumentText
Dim fs As FileStream
fs = New FileStream("dump.txt", FileMode.Create, FileAccess.Write)
Dim s As New StreamWriter(fs)
s.Write(html)
s.Close()
fs.Close()
End Sub
End Class
In this configuration the code works fine, but user interaction is required after form load. The form has 3 buttons: login, dump, and exit. I would like to remove the buttons and let it all happen during the form1_load sub, but I get the following error:
Object reference not set to an instance of an object.
Even when I use thread.sleep(5000) before trying to fill the web form out (trying to let the page load) i still get the error. I also tried to put the initial wweb.navigate("http://www.website.com") in its own sub along with login and dump into their own subs while calling each from the form1_load sub. I still ran into the same error. By stepping through my code, I noticed that my windows form doesn't become visible until form1_load completes. So in essence, the browser doesn't have a page loaded. This to me means my calls on the web form objects (to fill them out and submit) don't exist until after form1_load completes.
So my problem is now how to get around this dilemma. It was suggested to me to use multi-threading, but i've never attempted it before and it seems too complicated for the problem. Any Thoughts?
Thanks in advance
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|