网页源文件里面用了iframe,但是iframe里面嵌套的页的代码没有包含在webbrowser的document里面,如何获取?iframe的嵌套也是用xml写出来的,所以没法找它的地址. 我是想获得嵌套页里面的input,好输入内容!
解决方案 »
- 怎样以记录文件的形式存储用户信息?
- longword 型变量怎样才能变成integer,我是用getdiskfreespace取磁盘剩余空间后得到longword后不知道怎么处理
- 关于映射文件的问题
- 如何将一个WideString中的Ascii码类型的字符转换为汉字的形式字符?
- 请教WebBrowser空间加载的网页,如何实现另存为
- 关于DBGRID中1个字段的下拉显示子表的问题,麻烦~~~~~~
- 如何获取工程中所有的窗口
- ADO Filter's BUG??
- 还有,怎样固定控件 ?
- mscom怎么用?
- 在先等待 50分--delphi中怎么在设置后memo组件的Wanttab=true后,设置按tab键缩进的字符个数
- RegisterServiceProcess在winxp下如何使用??
var i : integer;
Document : IHTMLDocument2;
Frames : IHTMLFramesCollection2;
Element : IHTMLElement;
ElementName : OLEVariant;
FrameWindow : IHTMLWindow2;
FrameDocument : IHTMLDocument2;
Dispatch : IDispatch;
FrameCount : Integer;
AnchorString : string ;
begin
if First then
begin
//Get the main document
Document:= FInternetExplorer.Document as IHTMLDocument2;
if not Assigned(Document) then
exit;
//After we retrieve the document, we get the number of frames
Frames:=Document.Get_Frames;
//Test if there has frames
if not assigned(Frames) then
exit;
for i:=0 to Document.all.length-1 do
begin
Element:=Document.all.item(i,0) as IHTMLElement;
if not assigned(Element) then
continue;
if Element.tagName = 'FRAME' then
begin
ElementName:=Element.getAttribute('Name',0);
inc(FrameCount);
FrameList.Items.add(ElementName);
try
Dispatch:=Frames.item(ElementName);
Dispatch.QueryInterface(IHTMLWindow2,FrameWindow);
if not assigned(FrameWindow) then
continue;
FrameDocument:=FrameWindow.document;
if assigned(FrameDocument) then
GetFramesLink(FrameDocument,false);
except
on EOLEException do
begin
FrameList.Items.Delete(FrameList.Count-1);
dec(FrameCount);
continue;
end;
end;
end //if=Frame
else
if Element.tagName = 'A' then
begin
AnchorString := Element.innerText;
if AnchorString = '' then
AnchorString := '(Empty Name)';
// We know that the element is an IHTMLAnchorElement since the tagName
// is 'A'.
AnchorString := AnchorString + ' - ' +
(Element as IHTMLAnchorElement).href;
lstbxLinks.Lines.Add(AnchorString);
end;
end; //For i Schleife
end
else
begin
if not assigned(CheckDoc) then
exit;
Frames:=CheckDoc.get_frames;
if not assigned(Frames) then
exit;
for i:=0 to CheckDoc.all.length-1 do
begin
Element:=CheckDoc.all.item(i,0) as IHTMLElement;
if not Assigned(Element) then
continue;
if Element.tagName = 'FRAME' then
begin
ElementName:=Element.getAttribute('Name',0);
inc(FrameCount);
FrameList.Items.Add(ElementName);
try
Dispatch:=Frames.item(ElementName);
Dispatch.QueryInterface(IHTMLWindow2,FrameWindow);
if not assigned(FrameWindow) then
continue;
FrameDocument:=FrameWindow.document;
if assigned(FrameDocument) then
GetFramesLink(FrameDocument,false);
except
on EOLEException do
begin
FrameList.Items.Delete(FrameList.Count-1);
dec(FrameCount);
continue;
end;
end;
end //if=FRAME
else
if Element.tagName = 'A' then
begin
AnchorString := Element.innerText;
if AnchorString = '' then
AnchorString := '(Empty Name)';
// We know that the element is an IHTMLAnchorElement since the tagName
// is 'A'.
AnchorString := AnchorString + ' - ' +
(Element as IHTMLAnchorElement).href;
lstbxLinks.Lines.Add(AnchorString);
end;
end; //For i Loop
end;
end;
var
doc:IHTMLDocument2;
begin
doc := WebBrowser1.Document as IHTMLDocument2;
memo1.text:=doc.body.innerHTML ;
NavigateFrameset(doc) ;
end;procedure TForm1.NavigateFrameset(document: IHTMLDocument2);
var
index: Integer;
ole_index: OleVariant;
frame_dispatch: IDispatch;
framed: IHTMLWindow2;
begin
if document = nil then
exit;
try
Application.MessageBox(
PChar('Content:' + String(document.body.innerHTML)),
PChar('URL: ' + String(document.URL)),MB_OK or
MB_ICONINFORMATION);
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;
import the "Microsoft HTML Object Library" (MSHTML.TLB) and include MSHTML_TLB in the unit's uses clause
这个问题困扰我很长时间,今天彻底解决了,希望和大家共享,绝对通过了,别怕麻烦,你拷贝过去,试验一下
可以显示所有frame
另外要道入 Microsoft HTML Object Library,安装,这个时间长一点,有时候你以为是
死机了,多等一会
可否具体一点!?