uses MSHTML;
// IHTMLDocument2 eines Frames ermitteln
function GetFrameDoc(doc: IHTMLDocument2; v: OleVariant): IHTMLDocument2;
var
win: IHTMLWindow2;
u: IUnknown;
begin
u := doc.frames.item(v);
if Assigned(u)
and Succeeded(u.QueryInterface(IHTMLWindow2, win))
then Result := win.Document
else Result :=
nil;
end;
// IHTMLTable nr. iTableNr eines IHTMLDocument2 ermitteln
function GetTable(doc: IHTMLDocument2; iTableNr: OleVariant;
var t: IHTMLTable): Boolean;
var
ec: IHTMLElementCollection;
e2: IHTMLElement2;
begin
Result := True;
e2 := doc.body
as IHTMLElement2;
ec := e2.getElementsByTagName('
table');
if ec.length > 0
then t :=
ec.item(iTableNr, null)
as IHTMLTable
else REsult := False;
end;
// Zellen einer Zeile in ein Stringgrid übertragen
procedure GetCells(tr: IHTMLTableRow; sg: TStringGrid;
index: Integer);
var
i: Integer;
ec: IHTMLElementCollection;
e: IHTMLElement;
s: TStrings;
begin
s := sg.Rows[
index];
s.Clear;
ec := tr.cells;
if sg.ColCount <
ec.Length
then
sg.ColCount :=
ec.length;
for i := 0
to Pred(
ec.length)
do
begin
e :=
ec.item(i, null)
as IHTMLElement;
s.Add(e.innerText);
end;
end;
// IHTMLTable in Stringgrid übertragen
procedure GetRows(t: IHTMLTable; sg: TStringGrid);
var
i: Integer;
ec: IHTMLElementCollection;
begin
ec := t.rows;
sg.RowCount :=
ec.length;
for i := 0
to Pred(
ec.length)
do
GetCells(
ec.item(i, null)
as IHTMLTableRow, sg, i);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
iDoc2 : IHTMLDocument2;
itable: IHTMLTable;
row: IHTMLTableRow;
i: Integer;
begin
if assigned(Webbrowser1.Document)
then
begin
iDoc2 := Webbrowser1.Document
as IHTMLDocument2;
if Assigned(iDoc2)
then
begin
iDoc2 := GetFrameDoc(iDoc2, 1);
// IHTMLDocument2 von frame Nr. 1 ermitteln
if Assigned(iDoc2)
then
begin
if Assigned(iDoc2)
then
if GetTable(iDoc2, 0, itable)
then // erste Tabelle
begin
GetRows(itable, Stringgrid1);
end;
end;
end;
end;
end;