网页源文件里面用了iframe,但是iframe里面嵌套的页的代码没有包含在webbrowser的document里面,如何获取?iframe的嵌套也是用xml写出来的,所以没法找它的地址.  我是想获得嵌套页里面的input,好输入内容!

解决方案 »

  1.   

    补充一下,xml的内容是通过点击图片按纽出现的.
      

  2.   

    procedure TMainFrm.GetFramesLink(CheckDoc: IHTMLDocument2; First: boolean);
    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;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    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
      

  4.   

    uses MSHTML_TLB  在uses 加上MSTHML_TLB
    另外要道入  Microsoft HTML Object Library,安装,这个时间长一点,有时候你以为是
    死机了,多等一会
      

  5.   

    Microsoft HTML Object Library怎么装呀!?
    可否具体一点!?