1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
function GetFrameSource(WebDoc: iHTMLDocument2): string;
//returns frame HTML and scripts as a text string
var re: integer;
HTMLel : iHTMLElement;
HTMLcol : iHTMLElementCollection;
HTMLlen : Integer;
//ScriptEL : IHTMLScriptElement;
begin
result := '';
HTMLcol := WebDoc.Get_all;
HTMLlen := HTMLcol.length;
for re := 0 to HTMLlen - 1 do
begin
HTMLel := HTMLcol.item(re,0) as iHTMLElement;
if HTMLEl.tagName = 'HTML' then
result := result + HTMLEl.outerHTML;
end;
end;
function GetBrowserForFrame(Doc:IHTMLDocument2;nFrame:integer):IWebBrowser2;
//returns an interface to the frame's browser
var pContainer:IOLEContainer;
enumerator:IEnumUnknown;
nFetched: PLongInt;
unkFrame: IUnknown;
begin
result:=nil;
nFetched:=nil;
//Cast the page as an OLE container
pContainer := Doc as IOleContainer;
//Get an enumerator for the frames on the page
pContainer.EnumObjects(OLECONTF_EMBEDDINGS,enumerator);
//Now skip to the frame we're interested in
enumerator.skip(nFrame);
//and get the frame as IUnknown
enumerator.next(1,unkFrame,nFetched);
//Now QI the frame for a WebBrowser Interface - I'm not
//entirely
//sure this is necessary, but COM never ceases to surprise me
unkframe.QueryInterface(IID_IWebBrowser2,result);
end;
function GetSource : string;
//return the source for all frames in the browser
var Webdoc, HTMLDoc : ihtmldocument2;
framesCol : iHTMLFramesCollection2;
FramesLen : integer;
pickFrame : olevariant;
p: integer;
begin
try
WebDoc := WebBrowser1.Document as IHTMLDocument2;
result := GetFrameSource(WebDoc);
//Handle multiple or single frames
FramesCol := WebDoc.Get_frames;
FramesLen := FramesCol.Get_length;
if FramesLen > 0 then
for p := 0 to FramesLen-1 do
begin
pickframe := p;
HTMLDoc := Webbrowser1.Document as iHTMLDocument2;
WebDoc := GetBrowserForFrame(HTMLDoc, 1).document as iHTMLDocument2;
if WebDoc <> nil then
result := result + GetFrameSource(WebDoc);
end;
except
result := 'No Source Available';
end;
end; |
Partager