WebBrowser1.DocumentText

  • Thread starter Thread starter nime
  • Start date Start date
N

nime

How can I grab html source of a frame?

I can retrive main frame by WebBrowser1.DocumentText
but I want to retrive inner (child) frame...

WebBrowser1.Document.Window.Frames(0).DocumentText like thing doesn't exist...
 
How can I grab html source of a frame?

I can retrive main frame by WebBrowser1.DocumentText
but I want to retrive inner (child) frame...

WebBrowser1.Document.Window.Frames(0).DocumentText like thing doesn't exist...
See if this helps:

Private LinksTable As Hashtable

Private Sub WebBrowser1_DocumentCompleted(ByVal _
sender As Object, ByVal e As _
System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _
Handles WebBrowser1.DocumentCompleted

GetLinksFromFrames()

End Sub

Private Sub GetLinksFromFrames()
LinksTable = New Hashtable()
Dim FrameUrl As String

If (Not WebBrowser1.Document Is Nothing) Then
With WebBrowser1.Document
Dim CurrentWindow As HtmlWindow = .Window
If (CurrentWindow.Frames.Count > 0) Then
For Each Frame As HtmlWindow In _
Frame.Document.Links
FrameUrl = Frame.Url.ToString()

Dim ThisFrameName As String = Frame.Name
Dim ThisFrameDocument As _
HtmlDocument = Frame.Document

Dim FrameLinksHash As New Hashtable()
LinksTable.Add(FrameUrl, FrameLinksHash)

For Each HrefElement As HtmlElement In _
Frame.Document.Links
FrameLinksHash.Add(HrefElement.GetAttribute _
("HREF"), "Url")
Next
Next
Else
Dim DocLinksHash As New Hashtable()
LinksTable.Add(.Url.ToString(), DocLinksHash)

For Each HrefElement As HtmlElement In .Links
DocLinksHash.Add(HrefElement.GetAttribute _
("HREF"), "Url")
Next
End If
End With
End If
End Sub


Gene
 
nime said:
How can I grab html source of a frame?

I can retrive main frame by WebBrowser1.DocumentText
but I want to retrive inner (child) frame...

WebBrowser1.Document.Window.Frames(0).DocumentText like thing doesn't
exist...

\\\
For Each Frame As HtmlWindow In Me.WebBrowser1.Document.Window.Frames
MsgBox(Frame.Document.All(1).OuterHtml)
Next Frame
///
 
Cor Ligthert said:
You are number three asking this in this newsgroup. In my idea you cannot
do that with the new webbrowser (it is missing downloadcomplete).

What about this solution?

\\\
Private Sub WebBrowser1_DocumentCompleted( _
ByVal sender As Object, _
ByVal e As WebBrowserDocumentCompletedEventArgs _
) Handles WebBrowser1.DocumentCompleted
If Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
MsgBox("Document and frames loaded!")
End If
End Sub
///
 
Thank you for your valuable responses.

I am currently using WebBrowser control to automate a few things like auto-login a site, etc.


I don't know what is the difference between Navigated and DocumentComplete events, plus
in my application, DocumentComplete event never fired yet... Then I used Navigated instead.
But the problem is that the document is incomplete. I've examined Document.body.innerHTML
and only a part of the source appears...

Private Sub WebBrowser1_Navigated(...)

Select Case e.Url.ToString

Case "http://www.domain.com/"

''''ProcessMainPage() ' Do nothing

Case "http://www.domain.com/login.asp" 'Login frame

ProcessLoginPage()

End Select

End Sub

Private Sub ProcessLoginPage()

Dim frm as HTMLDocument
Dim el as HTMLElement

For i = 0 To WebBrowser1.Document.Window.Frames.Count - 1

'Find the login frame
If WebBrowser1.Document.Window.Frames(i).Document.Window.Url.ToString = "http://www.domain.com/login.asp" Then
frm = WebBrowser1.Document.Window.Frames(i).Document

'Fill the form
For Each el In frm.Forms
Select Case el.Name
Case "login"
el.InnerText = "username"
Case "pass"
el.InnerText = "secret"
End Select
Next el



End If

Next i

End Sub
 
This event never fired here : (

Herfried K. Wagner said:
What about this solution?

\\\
Private Sub WebBrowser1_DocumentCompleted( _
ByVal sender As Object, _
ByVal e As WebBrowserDocumentCompletedEventArgs _
) Handles WebBrowser1.DocumentCompleted
If Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
MsgBox("Document and frames loaded!")
End If
End Sub
///
 
Cor Ligthert said:
Did you try it, if it works than it is a great one?

Yes, it worked for the framesets I tested on the Web, but I am not sure if
it will still work if one of the frames contains a media stream or similar
that is still loading after the actual /documents/ have been loaded.
 
Document.Body.outerHTML gets reformatted / non-original
and INCOMPLETE html code. Looks like buggy : (
 
"> Document.Body.outerHTML gets reformatted / non-original
and INCOMPLETE html code. Looks like buggy : (
No it gives complete HTML code however not always everything on a page.

Cor
 
I mean webbrowser1.document.body.innerHTML has a bug here

innerHTML contains no form and I cannot fill the fields....

I've checked url, and compared the html code. Webbrowser1
reformats the tags and removes many lines. I call it as bug,
my form has been cropped : (

Then I tried Mozilla control, it has no problem, it parses everything
with no loss, but I couldn't use it, for example document.all.count
had an error...
 
nime said:
I mean webbrowser1.document.body.innerHTML has a bug here

innerHTML contains no form and I cannot fill the fields....

I've checked url, and compared the html code. Webbrowser1
reformats the tags and removes many lines. I call it as bug,
my form has been cropped : (

Maybe HTML Internet Explorer doesn't understand gets stripped from the
output and the result is simply the serialized part of the DOM tree.
 
But the browser's itself displays the form in my app ???

I've got another problem with Mozilla control. I cannot fill the form fields which they exist.

AxMozillaBrowser1.Document.All.Item("login").Value = "xx"

line causes this error:

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll


Private Sub AxMozillaBrowser1_DocumentComplete(ByVal sender As Object, ByVal e As
AxMOZILLACONTROLLib.DWebBrowserEvents2_DocumentCompleteEvent) Handles AxMozillaBrowser1.DocumentComplete

If e.uRL.ToString = "http://www.domain.com/login.asp" Then
AxMozillaBrowser1.Document.All.Item("login").Value = "xx"
AxMozillaBrowser1.Document.All.Item("pass").Value = "xxx"

End If

End Sub
 
1. Mozilla Activex control doesn't support all of
properties/methods/elements/etc.

2. IE WebBrowser control did not fire because I've blocked a few IP's
(via hosts file) and an ad related inner frame couldnt complete. So
WebBrowser1_DocumentComplete event did not fire. Now
I did unblock the IPs and event has been called again.

3. Now I have a new problem. Can you please read the topic:
WebBrowser: Programmaticaly click an image button ?

Thank you.



haber iletisinde þunlarý said:
But the browser's itself displays the form in my app ???

I've got another problem with Mozilla control. I cannot fill the form
fields which they exist.

AxMozillaBrowser1.Document.All.Item("login").Value = "xx"

line causes this error:

A first chance exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll


Private Sub AxMozillaBrowser1_DocumentComplete(ByVal sender As Object,
ByVal e As AxMOZILLACONTROLLib.DWebBrowserEvents2_DocumentCompleteEvent)
Handles AxMozillaBrowser1.DocumentComplete

If e.uRL.ToString = "http://www.domain.com/login.asp" Then
AxMozillaBrowser1.Document.All.Item("login").Value = "xx"
AxMozillaBrowser1.Document.All.Item("pass").Value = "xxx"

End If

End Sub
 
Herfried,

I can not reach you by mail. Can I use this in documentation (by instance
our website?)

Cor
 
Cor Ligthert said:
I can not reach you by mail.

Sorry, unfortunately I was too busy to answer emails :-(.
Can I use this in documentation (by instance
our website?)

Yes, you can use it, but I suggest to test the solution extensively.
 
Back
Top