Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

RetrieveHTML Proc Is there a mistake?

Post Reply
asparagas
Posts: 17
Joined: Sun Nov 24, 2019 11:36 pm

RetrieveHTML Proc Is there a mistake?

Post by asparagas »

The text I got from the RetrieveHTML procedure and the text image I got from context menu command vievpagesource is different! What is the reason for this? When I run the RetrieveHTML procedure 2 times I get the correct result!
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: RetrieveHTML Proc Is there a mistake?

Post by salvadordf »

TChromium.RetrieveHTML gets the HTML source from one frame. If we call it without parameters then it gets the HTML from the main frame only.

The "View page source" option in the context menu is not part of CEF. It's a Chromium function and I don't know how it's implemented.

If the web page changes the HTML source dinamically then TChromium.RetrieveHTML will return different results each time.

However, there could be an unexpected issue with this procedure too. Please, provide a step-by-step guide to reproduce this issue and I'll investigate.
asparagas
Posts: 17
Joined: Sun Nov 24, 2019 11:36 pm

Re: RetrieveHTML Proc Is there a mistake?

Post by asparagas »

Thank you for your interest.

I tried all kinds of

yes, the web page is dynamically changing the content. I wait for 5 minutes, for example, I get the old result with retrievehtml again, I get it with viewpagesource, it always gives the correct result without waiting !! Interesting..
asparagas
Posts: 17
Joined: Sun Nov 24, 2019 11:36 pm

Re: RetrieveHTML Proc Is there a mistake?

Post by asparagas »

I can't get the information I see on the screen from source code with retrievehtml !!
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: RetrieveHTML Proc Is there a mistake?

Post by salvadordf »

Try getting the HTML using JavaScript instead.
asparagas
Posts: 17
Joined: Sun Nov 24, 2019 11:36 pm

Re: RetrieveHTML Proc Is there a mistake?

Post by asparagas »

How is it going to be?

Can you sample if I request it very much?

I do not have that much information because ..
asparagas
Posts: 17
Joined: Sun Nov 24, 2019 11:36 pm

Re: RetrieveHTML Proc Is there a mistake?

Post by asparagas »

tried the following ways and got results, is there any more logical way?

-.-.-.-.-.-

solution - 1:

type
TUYAPTransferFrm = class(TForm)
private
_asBrowser_Text_ :string;
end;

procedure TUYAPTransferFrm.StringVisitor(const str: ustring);
begin
_asBrowser_Text_ := str;
end;

procedure TUYAPTransferFrm.Button5Click(Sender: TObject);
var _CefStringVisitor_ :ICefStringVisitor;
begin
_CefStringVisitor_ := TCefFastStringVisitor.Create(StringVisitor);
Chromium1.Browser.MainFrame.GetSource ( _CefStringVisitor_ );
end;

-.-.-.-.-

solution - 2:

PostMessage(Handle, MINIBROWSER_COPYHTML, 0, 0);
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: RetrieveHTML Proc Is there a mistake?

Post by salvadordf »

The code you posted with a string visitor is almost identical to the code behind the TChromium.RetrieveHTML function.

There are other ways but they have similar complexity :
  • JSExtension uses "innerHTML" in JavaScript and sends the results using a JavaScript extension : https://github.com/salvadordf/CEF4Delphi/blob/47fb09e887ced6803c59d2f573eca632b888ffa0/demos/Delphi_VCL/JavaScript/JSExtension/uJSExtension.pas#L391
  • The DevTools protocols has a method to get the HTML but it requires several steps to get the node IDs. I haven't tried this :
    https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getOuterHTML
asparagas
Posts: 17
Joined: Sun Nov 24, 2019 11:36 pm

Re: RetrieveHTML Proc Is there a mistake?

Post by asparagas »

thank you so much. I found the different solution in the "JavaScript \ JSEval" example .. best regards
Post Reply