Newb AxWebBrowser question

  • Thread starter Thread starter tommydogs
  • Start date Start date
T

tommydogs

I am just starting out with AxWebBrowser and need help with a simple
application. I just want to navigate to a web page, then read in
source code. Here's what I have so far:

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

AxWebBrowser1.Navigate("http://www.google.com")

End Sub

Private Sub AxWebBrowser1_DocumentComplete(ByVal sender As Object,
ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent)

' what do I put here to grab the source code?

End Sub



Could someone please provide a snippet of code (along with any
references I might need to add) that would load the page's source code
into a string?
 
Private Sub AxWebBrowser1_DocumentComplete(ByVal sender As Object,
ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent)

' what do I put here to grab the source code?

Dim src As String

src = AxWebBrowser1.Document.DocumentElement.OuterHtml

HTH,
 
Thank you for the quick response. I had tried something like that
already, but using your code it looks like I am still getting a NULL
return. For testing purposes, I am just trying to dump the results in
a textbox on the page (TextBox1), but I am just seeing the auto-created
"TextBox1" in TextBox1 when I use the following code:

Private Sub AxWebBrowser1_DocumentComplete(ByVal sender As Object,
ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent)

Dim src As String

src = AxWebBrowser1.Document.DocumentElement.OuterHtml

TextBox1.Text = src

End Sub


Am I making an obvious mistake?
 
Am I making an obvious mistake?

I suspect your code isn't being called... Have you tried putting a
breakpoint on the code within the event handler?

The procedure declaration in the code that you quoted:

\\\
Private Sub AxWebBrowser1_DocumentComplete(ByVal sender As Object,
ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent)
///

....is incomplete. You have declared a Private Sub, but you haven't specified
that it should handle the DocumentComplete event of the browser control.

Try adding the "Handles" clause, so that the procedure declaration looks
like this:

\\\
Private Sub AxWebBrowser1_DocumentComplete(ByVal sender As Object, _
ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) _
Handles AxWebBrowser1.DocumentComplete
///

(Note the additional code in the third line). Then see if your code gets
executed.

HTH,
 
Thanks, that was it!! I had that code (Handles) in the original
version of my project, but somehwere in my frustrated monkeying around
it got lopped off.
 
I have a question about the event "DocumentCompleteEvent" of AxWebBrowser.
My code as follows, it will trigger two times(speaking "Loading completed"
twice) when I submit a URL to handle. Why? Any suggestion?

Private Sub WB_DocumentComplete(ByVal sender As Object, ByVal e As
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) Handles
WB.DocumentComplete
tts.Speak("Loading completed.") 'Text-to-Speech engine call
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top