views:

1640

answers:

3

Here's the issue:

I have a hook in IE that reacts on WebBrowser.OnNavigateComplete2 event to parse the content of the document for some precise info.

That document contains frames, so I look into the HTMLDocument.frames. For each one, I look into the document.body.outerHTML property to check for the content.

Problem is, the string I'm looking for never shows there, whereas it is displayed in the finale page. So, am I looking in the wrong place? If it is displayed when the page is fully loaded, then it's downloaded at some point, right? But in which object should I look ?

BTW, I Don't know if that is of any importance, but the page I'm searching into comes from a ASP.NET application.

public void OnNavigateComplete2(object pDisp, ref object url)
{
    document = (HTMLDocument)webBrowser.Document;

    mshtml.FramesCollection frames = document.frames;
    for (int i = 0; i < frames.length; i++)
    {
        object refIdx = i;
        IHTMLWindow2 frame = (IHTMLWindow2)frames.item(ref refIdx);
        string frameContent = frame.document.body.outerHTML;
    }
}

Thank your for your help.


@rams This event is launched many times for each page, so I figured it was each time a framed is loaded, even if i don't get to catch the one I'm looking for. If not, what would be the event to catch the frames content?

What I want to do is detect some precise info on a precise frame, then save it. later, a web page is loaded triggered by some user action, where I need the info I got from parsing the frame.

A: 

Are you using some kind of threading? Running the browser in a separate thread really messes up things. Try to execute it in an STAThread and check if you get the correct result.

Gonzalo Quero
I don't use any threading, at least explicitely. Is there some way to check this/force execution in same thread?
Antoine
A: 

The reason your string does not show is because of the frame. The web browser control fires the document navigate complete event after it has loaded the main document. At this point, the frames haven't yet requested their sources. After the document is parsed by the web browser control, requests for the frame sources are issues and downloaded.

Can you please describe what you are trying to accomplish?

rams
A: 

Do you know the name/id of the frame you are looking for content? If so, in your navigateComplete2 event, can you get a reference to the frame like

iFrame frm = document.frames(<your frame id>);

int readyState=0;

while(frm.readystate !=4){
// do nothing. be careful to not create an endless loop
}

if(frm.readyState==4){
   // get your content now
}

HTH

rams
I look into this, thx.
Antoine