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

前端 未结 2 848
情话喂你
情话喂你 2020-12-11 05:49

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 re

相关标签:
2条回答
  • 2020-12-11 06:00

    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;
    
    0 讨论(0)
  • 2020-12-11 06:12

    I Googled this problem and I can find a good code for this:

    Idoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
    try
      IDoc.designMode := 'on';
      while IDoc.readyState <> 'complete' do
        Application.ProcessMessages;
      v := VarArrayCreate([0, 0], VarVariant);
      v[0] := MyHTML;
      IDoc.Write(PSafeArray(System.TVarData(v).VArray));
      IDoc.designMode := 'off';
      while IDoc.readyState <> 'complete' do
        Application.ProcessMessages;
    
      ParseHTML(IDoc);
    finally
      IDoc := nil;
    end;
    

    Regards

    0 讨论(0)
提交回复
热议问题