Get HTML Source from Chromium Embedded

2019-01-19 01:13发布

问题:

How to do this with Delphi Chromium Embedded Component i know how to do this with TWebBrowser. But since no docs are present for this I am sure someone else had same problem.

Thanks

回答1:

Here is how you do it..

procedure TCustomLoad.OnLoadEnd(const browser: ICefBrowser;
  const frame: ICefFrame; httpStatusCode: Integer);
  var
  data:tstringlist;
begin
  data:=tstringlist.create;
  if frame.IsMain then
  data.text:=frame.Source; // HTML Source    
end;
  data.free;
end;


回答2:

in dcef 3

procedure StringVisitor(const str: ustring);
begin
  //str is the SourceHtml
showmessage(str);
end;

function GetSourceHTML: string;
var
CefStringVisitor:ICefStringVisitor;
begin
  CefStringVisitor := TCefFastStringVisitor.Create(StringVisitor);
  Chromium1.Browser.MainFrame.GetSource(CefStringVisitor);
end;


回答3:

I really would like to add this as comment, but i don't have enough reputation. :/ Anyway - because i check html source quite offten, i declare

CefStringVisitor := TCefFastStringVisitor.Create(StringVisitor);

once at program begining, and then use only

function GetSourceHTML: string;
begin
  Chromium1.Browser.MainFrame.GetSource(CefStringVisitor);
end;

I would like to ask if there is something i should know about it - maybe it's a bad idea?