Ver Mensaje Individual
  #3  
Antiguo 22-10-2012
Avatar de kotai
kotai kotai is offline
Miembro
 
Registrado: mar 2004
Ubicación: Gandia
Posts: 31
Reputación: 0
kotai Va por buen camino
Si, sigo usando Delphi 2006.

De todas formas ya lo solucioné, importé el ActiveX "Microsoft HTML Object Library" que me hizo un MSHTML_TLB.pas con la clase IHTMLDocument2 que también permite leer el código fuente de los frames:

Código Delphi [-]
//******************************************************************************

function GetBrowserForFrame(Doc: IHTMLDocument2; nFrame: Integer): IWebBrowser2;
var
   pContainer: IOLEContainer;
   enumerator: ActiveX.IEnumUnknown;
   nFetched: PLongInt;
   unkFrame: IUnknown;
   hr: HRESULT;
begin
     Result := nil;
     nFetched := nil;
     // Cast the page as an OLE container
     pContainer := Doc as IOleContainer;
     // Get an enumerator for the frames on the page
     hr := pContainer.EnumObjects(OLECONTF_EMBEDDINGS or OLECONTF_OTHERS, enumerator);
     if hr <> S_OK then
     begin
          pContainer._Release;
          Exit;
     end;
     // Now skip to the frame we're interested in
     enumerator.Skip(nFrame);
     // and get the frame as IUnknown
     enumerator.Next(1,unkFrame, nFetched);
     // Now QI the frame for a WebBrowser Interface - I'm not  entirely
     // sure this is necessary, but COM never ceases to surprise me
     unkframe.QueryInterface(IID_IWebBrowser2, Result);
end;

//******************************************************************************

function GetFrameSource(WebDoc: iHTMLDocument2): string;
  //returns frame HTML and scripts as a text string
var
   re: integer;
   HTMLel: iHTMLElement;
   HTMLcol: iHTMLElementCollection;
   HTMLlen: Integer;
   ScriptEL: IHTMLScriptElement;
begin
     Result := '';
     if Assigned(WebDoc) then
     begin
          HTMLcol := WebDoc.Get_all;
          HTMLlen := HTMLcol.Length;
          for re := 0 to HTMLlen - 1 do
          begin
               HTMLel := HTMLcol.Item(re, 0) as iHTMLElement;
               if HTMLEl.tagName = 'HTML' then
                  Result := Result + HTMLEl.outerHTML;
          end;
     end;
end;

//******************************************************************************

procedure TF_Principal.ObtenerHTML(Num:SmallInt);
var
  Webdoc, HTMLDoc: ihtmldocument2;
  framesCol: iHTMLFramesCollection2;
  FramesLen: integer;
  pickFrame: olevariant;
  p: integer;
  HTML : String;
  iFrame : IWebBrowser2;
begin
     if WB <> nil then
        try
           WebDoc := WB.Document as IHTMLDocument2;
           HTML := GetFrameSource(WebDoc);
           // analizamos el HTML de la página principal
           AnalizarHTML(HTML);
           FramesCol := WebDoc.Get_frames;
           FramesLen := FramesCol.Get_length;
           if FramesLen > 0 then
              for p := 0 to FramesLen - 1 do
              begin
                   pickframe := p;
                   HTMLDoc   := WB.Document as iHTMLDocument2;
                   iFrame    := GetBrowserForFrame(HTMLDoc, pickframe);
                   if iFrame <> nil then
                   begin
                        WebDoc := iFrame.document as iHTMLDocument2;
                        if WebDoc <> nil then
                        begin
                             HTML := GetFrameSource(WebDoc);
                             // analizamos el HTML de este frame
                             AnalizarHTML(HTML);
                        end;
                   end;
              end;
        except
        end;
end;

Saludos.
Responder Con Cita