1. Computing & Technology

Discuss in my forum

Get the full HTML from the TWebBrowser component

By , About.com Guide

When using the TWebBrowser component you might want to grab the full HTML source code from the page being displayed by the component. Here's how:

~~~~~~~~~~~~~~~~~~~~~~~~~
uses mshtml;

var
    iall : IHTMLElement;
begin
   if Assigned(WebBrowser1.Document) then
   begin
     iall := (WebBrowser1.Document AS IHTMLDocument2).body;

     while iall.parentElement <> nil do
     begin
       iall := iall.parentElement;
     end;
     memo1.Text := iall.outerHTML;
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Note: HTML goes into a TMemo control named "Memo1".

Delphi tips navigator:
» How to start your favorite application directly from the Delphi IDE
« TForm.Create(?) Nil, Self or Application?

©2012 About.com. All rights reserved.

A part of The New York Times Company.