본문 바로가기
Application/Delphi Lecture

IE URL 찾기, Frame 안의 Url 도 찾는다.

by 현이빈이 2008. 8. 13.
반응형

uses

MSHTML_TLB, OleCtrls, SHDocVw, ExtCtrls, ActiveX


....



procedure TForm1.Button2Click(Sender: TObject);
var
   pvShell : IShellWindows;
   ovIE : OleVariant;
   i : Integer;

   ShellWin: TShellWindows;
   WB: IWebBrowser2;

   Doc: IHTMLDocument2;
  Container: IOleContainer;
  Enumerator: ActiveX.IEnumUnknown;
  Unknown: IUnknown;
  Browser: IWebBrowser2;
  Fetched: Longint;
  NewDoc: IHTMLDocument2;
  FrameSource: String;

  //WB: TWebBrowser;

begin
  ShellWin := TShellWindows.Create(nil);
  try
    for i := 0 to ShellWin.Count-1 do
    begin
      try
        ShellWin.Item(i).QueryInterface(IID_IWebBrowser2, WB);

        if (Supports(WB.Document, IHTMLDocument2, Doc)) then
        begin
          if (Supports(Doc, IOleContainer, Container)) and
             (Container.EnumObjects(OLECONTF_EMBEDDINGS, Enumerator) = S_OK) then
          begin
            while Enumerator.Next(1, Unknown, @Fetched) = S_OK do
            begin
              if (Supports(Unknown, IWebBrowser2, Browser)) and
                 (Supports(Browser.Document, IHTMLDocument2, NewDoc)) then
              begin
                ///////////////////////////////////////////////////////////
                // Here, NewDoc is an IHTMLDocument2 that you can query for
                // all the links, text edits, etc.
                //
                // Here, I'm just showing you how to get the innerHTML of
                // the Frame.
                ///////////////////////////////////////////////////////////

                if pos('canonclub4.fotocube.com:9000', WB.LocationURL) > 0 then
                begin
                  //Browser.Navigate2('http://daum.net', 0,0,0,0);
                  //Memo1.Lines.Add(Browser.LocationURL);
                end;
                {FrameSource := NewDoc.body.innerHTML;
                Memo1.Lines.Add(NewDoc.location.href);
                Memo1.Lines.Add('************************************************');
                Memo1.Lines.Add(FrameSource);
                Memo1.Lines.Add('************************************************');}
              end;
            end;
          end;
        end;
      except

      end;
    end;
  finally
    ShellWin.Free;
  end;

end;

반응형