如题
其实我是想建立完整的网页元素树,但是无法将 frame 和元素节点对应起来,父子结构无法体现,怎么办?
其实我是想建立完整的网页元素树,但是无法将 frame 和元素节点对应起来,父子结构无法体现,怎么办?
解决方案 »
- 5.4青年节看《南京!南京》有感
- 我在TServerSocket与TClientSocket的OnRead事件中发生的怪事!!!!
- 关于数据库组件
- 求fclabel控件
- ■□■ CAsoft 软件工程师入学考试试题 □那位高手帮我做阿?????????
- 高手请解读formulaone,谢谢了
- 大家来谈谈自己的工作环境吧
- 如何让用户只可修改DBGIRD中记录而不能通过“insert”键增加记录
- ADODataSet如何用做updata?
- 讨论报表控件大杂脆!各位FastReport有何不足之处!对于其子表的操作功能是否强大!相比之下还有没有其它更好的报表控件?
- 内存映射文件问题
- 为何时常在调试执行完程序反回到DELPHI中都会有CPU观察窗口出现
procedure TFMWebBrowser.RefreshHTMLElementTree;
function
_AddElementNode(AParent: TcxTreeListNode; AItem: IHTMLElement): TcxTreeListNode;
var
lCaption: string;
lDataElement: TDataElement;
begin
lCaption := '';
if Trim(AItem.className) <> '' then lCaption := ' class=' + AItem.className;
if lCaption = '' then lCaption := VarToStr(AItem.getAttribute('class', 0));
if Trim(AItem.id) <> '' then lCaption := ' id=' + AItem.id;
lCaption := '<' + AItem.tagName + lCaption + '>';
Result := AParent.AddChild;
Result.Values[0] := lCaption;
lDataElement := TDataElement.Create;
lDataElement.PElement := AItem;
Result.Data := lDataElement;
end;
procedure
_FullChildItem(AParent: TcxTreeListNode; AItem: IHTMLElement);
var
M, N: Integer;
lChilds: IHTMLElementCollection;
lItem: IHTMLElement;
lThisFrame: IHTMLWindow2;
lFrame: IDispatch;
lItemNode: TcxTreeListNode;
lurl, lsrc: string;
begin
lChilds := AItem.children as IHTMLElementCollection;
for M := 0 to lChilds.Length - 1 do
begin
lItem := lChilds.Item(M, varEmpty) as IHTMLElement;
lItemNode := _AddElementNode(AParent, lItem);
if (lItem.tagName = 'IFRAME') or (lItem.tagName = 'FRAME') then
begin
lThisFrame := nil; //下面的代码也无法使 lItem 和 IHTMLWindow4 联系起来
for N := 0 to (lItem.document as IHTMLDocument2).frames.length - 1 do
begin
lFrame := (lItem.document as IHTMLDocument2).frames.item(N);
lurl := (lFrame as IHTMLWindow4).frameElement.src;
lsrc := lItem.getAttribute('src', 0);
if CompareText(RightStr(lurl, Length(lsrc)), lsrc) = 0 then //比较src有时候不行,如果比较name有时候会重复
begin
lThisFrame := lFrame as IHTMLWindow2;
Break;
end;
end;
if lThisFrame <> nil then
begin
lItemNode := _AddElementNode(lItemNode, lThisFrame.Document.body);
_FullChildItem(lItemNode, lThisFrame.Document.body);
end;
end else
begin
if (lItem.children as IHTMLElementCollection).Length <> 0 then
_FullChildItem(lItemNode, lItem);
end;
end;
end;
var
lItemNode: TcxTreeListNode;
begin
ctlElementTree.Clear;
lItemNode := _AddElementNode(ctlElementTree.Root, (WebBrowser.Document as IHTMLDocument2).body);
_FullChildItem(lItemNode, (WebBrowser.Document as IHTMLDocument2).body);
end;