用下面的代码可以获取iframe里的代码,现在的问题如果iframe是嵌套的,怎么获取源代码呢,困扰很久了,望高人指点。usr mshtml;
procedure TMainForm.ToolButton56Click(Sender: TObject);
var
Index: Integer;
Document: IHTMLDocument2;
FrameIdx: OleVariant;
FrameDis: IDispatch;
FrameWin: IHTMLWindow2;
begin
while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do
Application.ProcessMessages; if WebBrowser1.Document = nil then Exit;
if WebBrowser1.Document.QueryInterface(IHTMLDocument2, Document) <> 0 then Exit;
if Document.frames.length > 0 then
begin
for Index := 0 to Document.frames.length - 1 do
begin
FrameIdx := Index;
FrameDis := Document.frames.item(FrameIdx);
if FrameDis.QueryInterface(IHTMLWindow2, FrameWin) <> 0 then Exit;
ShowMessage(FrameWin.document.body.outerHTML);
//FrameWin.document 就是你要的每个 Frame 的文档
end;
end;
end;
procedure TMainForm.ToolButton56Click(Sender: TObject);
var
Index: Integer;
Document: IHTMLDocument2;
FrameIdx: OleVariant;
FrameDis: IDispatch;
FrameWin: IHTMLWindow2;
begin
while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do
Application.ProcessMessages; if WebBrowser1.Document = nil then Exit;
if WebBrowser1.Document.QueryInterface(IHTMLDocument2, Document) <> 0 then Exit;
if Document.frames.length > 0 then
begin
for Index := 0 to Document.frames.length - 1 do
begin
FrameIdx := Index;
FrameDis := Document.frames.item(FrameIdx);
if FrameDis.QueryInterface(IHTMLWindow2, FrameWin) <> 0 then Exit;
ShowMessage(FrameWin.document.body.outerHTML);
//FrameWin.document 就是你要的每个 Frame 的文档
end;
end;
end;
解决方案 »
- DELPHI如何在其他程序的窗体上加控件
- 日期:[fDate] 单据号:[fNo] 怎么提取所有[]里的字符串 现场求解
- 大家看看这个Split函数错在哪里?
- 恭喜几位朋友,也是JR作了版主、大阪,还有些朋友、也是JR辞职了。散分
- 我是女生,我爱编程。找工作时会不会受耻视呀
- 如何使delphi6自带的installshield express支持中文?
- 换个new ID
- 怎样给TDataTime变量同时赋年月日时分秒?EncodeTime和EncodeDate只能赋一部分的值
- 问题简单,只要进来就可以拿分!!!
- 牛虻呼叫老鱼,老千,若在线,请速回。//牛虻
- 弱问:关于Delphi7与fastreport变量传递的问题?急!!!(解决后马上给分!)
- 如何让图片沿线路滑动?
procedure TForm1.Button1Click(Sender: TObject);
procedure pScanFrames(mHTMLDocument2: IHTMLDocument2);
var
vIndex: OleVariant;
I: Integer;
vDispatch: IDispatch;
begin
if not Assigned(mHTMLDocument2) then Exit;
Memo1.Lines.Add(mHTMLDocument2.body.outerHTML);
for I := 0 to mHTMLDocument2.frames.length - 1 do
begin
vIndex := I;
vDispatch := mHTMLDocument2.frames.item(vIndex);
pScanFrames((vDispatch as IHTMLWindow2).document);
end;
end;
begin
pScanFrames(WebBrowser1.Document as IHTMLDocument2);
end;
http://halfyawn.mblogger.cn
var
index: Integer;
ole_index: OleVariant;
frame_dispatch: IDispatch;
framed: IHTMLWindow2;
begin
if document = nil then
exit;
try
if document.body <> nil then
HtmlCode.Add(string(document.body.innerHTML) + document.URL);
for index := 1 to document.Frames.Length do
try
ole_index := index - 1;
frame_dispatch := document.Frames.Item(ole_index);
if frame_dispatch <> nil then
begin
framed := frame_dispatch as IHTMLWindow2;
NavigateFrameset(framed.document);
end;
except
on E: Exception do
begin
end
end;
except
on E: Exception do
begin
Application.MessageBox(PChar(E.Message),
PChar('Exception'));
end;
end;
end;