How do I create an IHTMLDocument2 using a string from TIdHTTP?

SadeghAlavizadeh picture SadeghAlavizadeh · Aug 11, 2012 · Viewed 21.8k times · Source

I download a URL with IdHTTP.Get, and I need to search the HTML tags and extract some data.

How I can convert the string that IdHTTP.Get returns into an IHTMLDocument2?

Answer

Keeper picture Keeper · Aug 12, 2012

Try this one:

uses
  ... Variants, MSHTML, ActiveX;

var Cache: string;
    V: OleVariant;
    Doc: IHTMLDocument2;
begin
  ...

  Cache := IdHTTP.Get(url);
  Doc := coHTMLDocument.Create as IHTMLDocument2; // create IHTMLDocument2 instance
  V := VarArrayCreate([0,0], varVariant);
  V[0] := Cache;
  Doc.Write(PSafeArray(TVarData(v).VArray)); // write data from IdHTTP

  // Work with Doc
end;