简体   繁体   中英

Handle html without the use of TWebBrowser

Hello everybody I am reformulating the question, I'm getting a html with a tidhttp and working this html in a TWebBrowser this way:

(WebBrowser.Document as IHTMLDocument2).body.innerHTML := xHtml;
ovTable := WBT.OleObject.Document.all.tags('TABLE').item(1);

where ovTable is OleVariant;

more I want to do the same without having to use the TWebBrowser because it is consuming a lot of memory when created, I'm trying 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] := xHtml;
    IDoc.Write(PSafeArray(System.TVarData(v).VArray));
    IDoc.designMode := 'off';
  finally
    IDoc := nil;
  end;

Now, how do I get data from tables with the IDoc?

ovTable := Idoc.??

thanks!

Now, how do I get data from tables with the IDoc?

IDoc is an IHTMLDocument2 interface, same as WebBrowser.Document (it is just wrapped inside an OleVariant ), so you can use similar searching code. You just have to take into account that your IDoc approach is using early binding via static interface types at compile-time whereas your TWebBrowser approach is using late binding via OleVariant at run-time:

Idoc := CreateComObject(Class_HTMLDocument) as IHTMLDocument2;
try
  IDoc.designMode := 'on';
  while IDoc.readyState <> 'complete' do
    Application.ProcessMessages;
  v := VarArrayCreate([0, 0], varVariant);
  v[0] := xHtml;
  IDoc.Write(PSafeArray(System.TVarData(v).VArray));
  IDoc.designMode := 'off';
  ovTable := (IDoc.all.tags('TABLE') as IHTMLElementCollection).item(1, 0) as IHTMLTable; // <-- here
finally
  IDoc := nil;
end;

工作这个:

ovTable := (iDoc.all.tags('TABLE') as IHTMLElementCollection).item(1, 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM