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.

get html data from an iframe nested inside another iframe

Post Reply
79vivien@gmail.com
Posts: 1
Joined: Thu Nov 02, 2023 12:14 pm

get html data from an iframe nested inside another iframe

Post by 79vivien@gmail.com »

Hello! I had this problem:
There is a site, it has an iframe, in this iframe there is also an iframe from which I would like to receive data.
I tried RetievHTML, but it only returns the code of the first level iframe (and even then, it still needs to be found, since there are dozens of iframes on the first level and without id).
I liked the MiniBrowser example, the point about saving in mhtml, but unfortunately it brings up a dialog box for saving the page, and I would like to save the file in the background for later processing.

P.S. Sorry, i`m find calling the save dialog box in TMiniBrowserFrm.DevToolsDataAvailableMsg, but that's it, is it possible to somehow get the html in another way.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: get html data from an iframe nested inside another iframe

Post by salvadordf »

Hi,

CEF allows us to get the HTML in 3 ways :
  • Calling TChromiumCore.RetrieveHTML and getting the result in TChromiumCore.OnTextResultAvailable. This is usually the easiest method but if you have several frames then you need a few extra steps to get the the frame id or name. It's described below.
  • Using JavaScript to get the HTML and send it to Delphi. The DOMVisitor demo has a complete example. If you have several frames then you need to call TChromiumCore.ExecuteJavaScript with the frame id or name.
  • Using the "DOM.getOuterHTML" DevTools method. https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getOuterHTML . This is the most complicated method because you need to call several DevTool methods to get the right "NodeId" parameter.
To get the frame id you can set the focus of any HTML element in that frame and then use the GlobalCEFApp.OnFocusedNodeChanged event.
That event has a "frame" argument and you can read the ID from "frame.Identifier".
This event is called in the RENDER process and you will need to send the frame ID to the MAIN process using a console message or registering a JavaScript extension. See the Delphi_VCL\DOMVisitor demo and the Delphi_VCL\JavaScript\JSExtension demo for all the details.

In order to set the focus on an element you can simulate a mouse click or some TAB key presses.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: get html data from an iframe nested inside another iframe

Post by dilfich »

Forgot about the 4th method is "ResponseFilterBrowser" :)
It can also not be called prosmty, but it is the most effective.
the frame is usually a separate link and for optimization, you can set a filter based on the example of loading a script.
Student
Posts: 72
Joined: Tue Aug 07, 2018 9:20 am

Re: get html data from an iframe nested inside another iframe

Post by Student »

And here's the 5th method OnGetResourceHandler, you can also get the contents of any resource, and perform any manipulations with them. :geek:
Post Reply