簡體   English   中英

在不使用TWebBrowser的情況下處理html

[英]Handle html without the use of TWebBrowser

大家好,我正在重新解釋這個問題,我正在獲取一個帶有tidhttp的html,並以這種方式在TWebBrowser中使用此html:

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

其中ovTable是OleVariant;

我想做更多的事情而不必使用TWebBrowser,因為它在創建時會占用大量內存,我正在嘗試這樣做:

  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;

現在,如何使用IDoc從表中獲取數據?

ovTable := Idoc.??

謝謝!

現在,如何使用IDoc從表中獲取數據?

IDoc是一個IHTMLDocument2接口,與WebBrowser.Document相同(它只是包裝在OleVariant ),因此您可以使用類似的搜索代碼。 您只需要考慮到IDoc方法在編譯時通過靜態接口類型使用早期綁定 ,而TWebBrowser方法在運行時通過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;

工作這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM