uses ComObj,OleCtrls, SHDocVw_TLB,
ActiveX,MSHTML_TLB;
// kA ob ActiveX unbedingt dabei sein muss
var
vIE : OleVariant;
Memo2: TMemo;
// Internet Explorer Instanz wird erstellt und die Adresse in Edit1.text aufgerufen
procedure TForm1.Button2Click(Sender: TObject);
begin
vIE := CreateOleObject('
InternetExplorer.Application');
vIE.visible:=true;
vIe.navigate(Edit1.text);
sleep(3000);
Button3.Click;
end;
// Quellcode holen
function GetHTMLCode(WB: IWebbrowser2; ACode: TStrings): Boolean;
var
ps: IPersistStreamInit;
s:
string;
ss: TStringStream;
sa: IStream;
begin
ps := WB.document
as IPersistStreamInit;
s := '
';
ss := TStringStream.Create(s);
try
sa:= TStreamAdapter.Create(ss, soReference)
as IStream;
Result := Succeeded(ps.Save(sa, Bool(True)));
if Result
then ACode.Add(ss.Datastring);
finally
ss.Free;
end;
end;
// Das Aktuelle Internet Explorer Fenster wird gesucht
procedure TForm1.Button3Click(Sender: TObject);
var
ShellWindow: IShellWindows;
WB: IWebbrowser2;
spDisp: IDispatch;
IDoc1: IHTMLDocument2;
k: Integer;
s:
string;
a:integer;
begin
Memo2.clear;
ShellWindow := CoShellWindows.Create;
// get the running instance of Internet Explorer
for k := 0
to ShellWindow.Count
do
begin
spDisp := ShellWindow.Item(k);
if spDisp =
nil then Continue;
// QueryInterface determines if an interface can be used with an object
spDisp.QueryInterface(iWebBrowser2, WB);
if WB <>
nil then
begin
WB.Document.QueryInterface(IHTMLDocument2, iDoc1);
if iDoc1 <>
nil then
begin
WB := ShellWindow.Item(k)
as IWebbrowser2;
begin
// Add HTML Code to Memo
GetHTMLCode(WB, Memo2.Lines);
end;
end;
end;
end;
end;
// irgendwann dann den IE wieder schließen
vIE.quit;