iana1uk
asked on
Get html source from a frame within an Internet Explorer page
Hi, I need a procedure that will get the source html from within a frame on a web page in an already open instance of Internet Explorer, the problem is that the page contains frames. I don't need anything complicated, the frame will always be the same one. The source html then needs to be dumped into a TMemo. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Got a URL for me to test on? I tested on http://reportman.sourceforge.net/doc/index.html, only framed site I knew of OTTOMH.
ASKER
Hi Eddie, problem solved, it might be an untidy hatchet job, but it seems to do what I need. I've used some of your code above, the points are yours, thanks for your help! Ian.
procedure TForm1.Button5Click(Sender : TObject);
var
ShellWin : TShellWindows;
i,x : integer;
IE : IWebBrowser2;
Document: IHTMLDocument2;
Frame: IDispatch;
FrameNum: OleVariant;
FrameDoc: IHTMLDocument2;
begin
ShellWin := TShellWindows.Create(nil);
for i := 0 to ShellWin.Count-1 do
begin
ShellWin.Item(i).QueryInte rface(IID_ IWebBrowse r2, IE);
Document := IE.Document as IHTMLDocument2;
end;
try
x := Document.Frames.Length;
if x <> 0 then
for x := 0 to x - 1 do
try
FrameNum := x;
Frame := Document.Frames.Item(Frame Num);
FrameDoc := (Frame as IHTMLWindow2).Document as IHTMLDocument2;
Memo1.Text := FrameDoc.Get_body.Get_oute rHTML;
except
end;
except
end;
Document := nil;
ShellWin.Free;
end;
procedure TForm1.Button5Click(Sender
var
ShellWin : TShellWindows;
i,x : integer;
IE : IWebBrowser2;
Document: IHTMLDocument2;
Frame: IDispatch;
FrameNum: OleVariant;
FrameDoc: IHTMLDocument2;
begin
ShellWin := TShellWindows.Create(nil);
for i := 0 to ShellWin.Count-1 do
begin
ShellWin.Item(i).QueryInte
Document := IE.Document as IHTMLDocument2;
end;
try
x := Document.Frames.Length;
if x <> 0 then
for x := 0 to x - 1 do
try
FrameNum := x;
Frame := Document.Frames.Item(Frame
FrameDoc := (Frame as IHTMLWindow2).Document as IHTMLDocument2;
Memo1.Text := FrameDoc.Get_body.Get_oute
except
end;
except
end;
Document := nil;
ShellWin.Free;
end;
Oh, DAMN, I forgot about the IHTMLWindow2 object. I'm surprised that IE Security let you do it, though.
ASKER
I knew of it but didn't quite know how it worked. I borrowed a couple of lines of code from the IESnifferAutoFill components. I'm just happy it's now doing what I want!
ASKER
The frames are called using a relative URL.
Another point is that the page being retrieved has to be the one that is currently displayed as it is returning information that is different every time it is called.