在不使用TWebBrowser的情况下处理html

时间:2015-06-15 22:23:37

标签: delphi twebbrowser ihtmldocument2

大家好,我正在重新提出这个问题,我正在获取一个带有tidhttp的html并以这种方式在TWebBrowser中处理这个html:

  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;

其中ovTable是OleVariant;

更多我想做同样的事情而不必使用TWebBrowser,因为它在创建时消耗了大量内存,我正在尝试这个:

ovTable := Idoc.??

现在,如何从具有IDoc的表中获取数据?

fscanf

谢谢!

2 个答案:

答案 0 :(得分:1)

  

现在,如何从具有IDoc的表中获取数据?

IDocIHTMLDocument2接口,与WebBrowser.Document相同(它只包含在OleVariant内),因此您可以使用类似的搜索代码。您只需要考虑到您的IDoc方法在编译时通过静态接口类型使用早期绑定,而您的TWebBrowser方法正在使用后期绑定< / strong>在运行时通过OleVariant

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;

答案 1 :(得分:0)

工作:

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