views:

1413

answers:

6

How can I get source code of page thru WebBrowser Control (ActiveX InternetExplorer)?

I have an xml document "foo.xml".

var
 Web: TWebBrowser;
begin
 ...
 Web.Navigate("foo.xml");
 // How can I get source code thru WebBrower control<----
 ...
end;
+1  A: 

I thought this would be easy but it seems it might have been forgotten. You can easily do it with a TidHTTP control though.

MyPage := IdHTTP1.Get('www.google.com');

I know its not what you want but might help.

Toby Allen
I know it. But I want to know how it done with WebBrowser.
A: 

In the DocumentCompleted event, look at the DocumentText property of the WebBrowser control. It should have the complete text of the loaded page.

Jim H.
I see no such property in Delphi 2005. Was it introduced in a later version?
Rob Kennedy
A: 
IHTMLDocument2(Web.Document).Body.InnerHTML;

This should return the source of the page.

corné
Won't that omit the HEAD element, as well as the opening and closing BODY tags?
Rob Kennedy
Don't work with XML content.
I guess your right.Maybe this helps you?:http://www.delphidabbler.com/articles?article=14
corné
Still don't work with XML content.
A: 

Another method which works well is to use Synapse. Use the synapse call HttpGet to retrieve your initial resource (which gives you the source code) then manipulate as needed.

Another option would be to use the EmbeddedWB component which exposes MANY more properties and features of the web browser than the standard Delphi component does and still fits your requirement of doing it within the web browser.

skamradt
Yes, but I want to know how can I do this thru ActiveX only.
I believe the EmbeddedWB component WRAPS IE, and includes full source. Its a good starting point to see how its done.
skamradt
A: 

To access the entire HTML of the page through your WebBrowser control use:

Web.Document.All[0].OutterHtml;
Rob
A: 
private void btnTest_Click(object sender, EventArgs e)
        {
            wbMain.Navigate("foo.xml");
            wbMain.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(testing);
        }

        private void testing(Object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            test = wbMain.DocumentText;
        }

I know this is a little late but this works for me. wbMain is the WebBrowser Object.

Paul J Warner