Question Show specific parts/lines of a webpage

brekke

Member
Joined
Oct 17, 2010
Messages
11
Location
Stavanger, Norway
Programming Experience
Beginner
Hi guys/girls..

First of all, thanks for the help i have recieved in here earlier..

Now to my problem.. I am creating a simple researcher application to access and store data. As of today it workes by entering a number into a text field and hit enter/button. The result then shows up in a non-menu webbrowser window. What i would like it to do was to exclude the web browser window, and instead show in a popup window inside the application. This should be rather easy, here's what i think might be a problem. I want only to show specific lines from the webpage, not the whole page. Is this possible in an easy way?

Thanks in advance!
 
This example puts all text lines in a web page in a listbox, the code can be used in DocumentCompleted event handler for the WebBrowser and the control can be hidden (Visible=false)
If Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
    Dim body As String = Me.WebBrowser1.Document.Body.InnerText
    Dim lines() As String = body.Split(vbNewLine.ToCharArray, StringSplitOptions.RemoveEmptyEntries)
    Me.ListBox1.Items.AddRange(lines)
End If

If something like this is relevant, you can change it to only display some of the lines instead of all.
 
Thanks alot JohnH!

Will try this later today...
But will this work if the webbrowser used is the system default and not a built in browser in the application?

EDIT:
Oh.. you use a hidden web browser handle, to load in the webpage in? Clever! :D
 
Last edited:
Hmm.. nothing happens after the webpage finish loading.
Tried to make the webpage visible just for now to see the progress. The webpage loads and when finish, nothing is happening.
Tried to simply just swap the Me.ListBox1.Items.AddRange(lines) with Me.close to see if it would quit when the webpage had been finished.

But i think your on to something here.. :)

EDIT:
Changed the "If Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then" to
"If Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete <> 1 Then"

That seems to send it off, but then it looks like it's having some problem with the next command line "Dim body As String = Me.WebBrowser1.Document.Body.InnerText" as it stops and shows a debug error: NullReferanceExcetpion was unhandled.

What does this mean?
 
Last edited:
Back
Top