Programming/Delphi

TWebBrowser 에서 HTML Script 가져오기

통통만두 2011. 1. 21. 13:26
반응형
// [1]
// uses SHDocVw, ActiveX
function GetScriptOfHTML(Web: TWebBrowser; HTML: TStrings) : Boolean;
var
  PersistStream: IPersistStreamInit;
  Stream: IStream;
  FileStream: TmemoryStream;
begin
  try
    if not Assigned(Web.Document) then
    begin
      Result := False;
      //ShowMessage('Document not loaded!');
      Exit;
    end;

    PersistStream := Web.Document as IPersistStreamInit;
    FileStream := TmemoryStream.Create;
    try
      Stream := TStreamAdapter.Create(FileStream, soReference) as IStream;
      if Failed(PersistStream.Save(Stream, True)) then
        //ShowMessage('SaveAs HTML fail!');
        Result := False;

      FileStream.Position := 0;
      HTML.Clear;
      HTML.LoadFromStream( FileStream );
      
    finally
      FileStream.Free;
    end;

  except
    Result := False;
  end;
end;

 
// [2]
web_Main.OleObject.Document.DocumentElement.InnerHTML;


1번 방법과 2번 방법을 소개했는데, 두 개의 차이점이 있다.

줄바꿈, 들여쓰기 등의 차이점이 있지만 중요한 것은..

page.asp?a=1&b=2 <-- 요것이 HTML안에 있다면,

1번은 아주 잘표현을 하지만, 2번은 깨져서 나온다. 아마도 String 에서 &B 이런식으로 하면 단축키(?)로 먹혀 버린다.

더 자세한 것은 살펴볼까 했지만,,, 귀차니즘의 압박으로 확인도 안해보고.. (워낙 덤벙거리는 성격이라 ㅠ_ㅠ)
반응형