编辑 将其缩小到这一行,
HTML := wb.OleObject.Document.documentElement.innerHTML;
这会消耗时间...如何加快速度?
使用以下代码,我的应用程序在尝试访问页面的 HTML (Delphi XE) 时可能会挂起 1-2 秒。
function Button1Click(Sender : TObject);
begin
wb.navigate('http://10.0.0.154/stats');
// Use a timer to poll the page - dont wait and process app messages
timer1.enabled := true;
end;
procedure Timer1Timer(Sender : TObject);
var
HTML : WideString;
begin
If GetHTML(HTML) = true then
begin
Timer1.enabled := false;
{ do something }
end;
end;
function GetHTML(var HTML : WideString) : boolean;
var
Document : IHTMLDocument2;
begin
HTML := '';
Result := false;
Document := wb.DOcument as IHTMLDocument2;
If Assigned(Document) then
begin
try
HTML := wb.OleObject.Document.documentElement.innerHTML;
Result := true;
except
Result := false;
end;
end;
end;
但是我注意到在我的 GetHTML 方法中可能需要 1-2 秒才能返回某些内容,并且它会锁定 UI。用 Delphi XE 查看 AQTime,它说方法调用很慢(1-2 秒)。它是零星的,我想知道当页面仍在加载中时它是否会失败。
我正在加载的页面是一个内部页面,充满了 javascript 和 500k 大,我不能使用 OnDocumentComplete 因为它在页面准备好之前触发,即使我对 ReadyState 进行检查,它仍然会提前触发。
任何人都可以阐明,如果他们有更快的方式我可以访问 TWebbrowser 的 HTML?