首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么枚举网页中的iframe

2012-12-30 
如何枚举网页中的iframe?vari: Integerov: OleVariantDisp: IDispatchFrame: IHTMLIFrameElementhr: H

如何枚举网页中的iframe?


var
  i: Integer;
  ov: OleVariant;
  Disp: IDispatch;
  Frame: IHTMLIFrameElement;
  hr: HRESULT;
begin
  for i := 0 to Doc2.frames.length - 1 do
  begin
    ov := i;
    Disp := Doc2.frames.item(ov);
    if Disp = nil then  Continue;

    hr := Disp.QueryInterface(IID_IHTMLFrameElement, Frame);
    if Succeeded(hr) and (Frame2 <> nil) then
    begin
      OutputDebugString(PChar('frame'));
    end;
  end;
end;

Doc2是TEmbeddedWB的属性,这种方式不行,明明网页里有iframe,if Succeeded(hr) and (Frame2 <> nil) then这一句总是失败。


var
  i: Integer;
  FrameBase: IHTMLFrameBase;
  Disp: IDispatch;
  Frame: IHTMLIFrameElement;
  Elements: IHTMLElementCollection;
  hr: HRESULT;
  ov: OleVariant;
begin
  Disp := Doc2.all.tags('iframe');
  if Disp = nil then  Exit;
  hr := Disp.QueryInterface(IID_IHTMLElementCollection, Elements);
  if Succeeded(hr) and (Elements <> nil) then
  begin
    for i := 0 to Elements.length - 1 do
    begin
      Disp := Elements.item(i, ov);
      if Disp = nil then  Continue;
      hr := Disp.QueryInterface(IID_IHTMLFrameBase, FrameBase);
      if Succeeded(hr) and (FrameBase<> nil) then
      begin
        hr := Disp.QueryInterface(IID_IHTMLIFrameElement, Frame);
        if Succeeded(hr) and (Frame <> nil) then
        begin
          OutputDebugString(PChar('frame'));
        end;
      end;
    end;
  end;
end;

这种方式也不行,能获取IHTMLFrameBase,IHTMLIFrameElement接口还是获取不到。
高手帮帮忙
[解决办法]
HTML不太懂,帮你顶顶先
[解决办法]
没有这样写过,也很久没接触HTML了,哎,如果可以获取到网页源代码的话:可以通过pos查找<iframe>数量来确定
[解决办法]

procedure TForm1.Button5Click(Sender: TObject);
var
        doc: IHTMLDocument2;
        iw: IHTMLWindow2;
        pindex: oleVariant;
        i: integer;
        dispatch:IDispatch;
        Hinput:IHTMLInputButtonElement;


        mElem: IHTMLElement;
begin
        doc := wb1.Document as IHTMLDocument2;

        pindex := 0;
        dispatch := doc.frames.item(pindex);
        Dispatch.QueryInterface(IHTMLWindow2,iw);

        for i:=0 to iw.document.all.Length-1 do
        begin
                dispatch := iw.document.all.item(i,0);
                if succeeded(Dispatch.QueryInterface(IHTMLInputButtonElement,hinput)) then
                begin
                        Dispatch.QueryInterface(IHTMLElement,mElem);
                        showmessage('click:' + mElem.outerHTML);
                        mElem.click;
                end;
        end;
end;


[解决办法]
框架好像获取不到的吧

热点排行