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 source from an Iframe

Post Reply
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Get source from an Iframe

Post by thefunkyjoint »

Hi,

When i use the RetrieveHtml method, it won't get the source of an Iframe of the page. How can i get the source of an specific Iframe inside the page ?

Thanks
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get source from an Iframe

Post by salvadordf »

Hi,

There are 3 overloaded versions of TChromium.RetrieveHTML :
  • TChromium.RetrieveHTML(const aFrameName : ustring = '');
  • TChromium.RetrieveHTML(const aFrame : ICefFrame);
  • TChromium.RetrieveHTML(const aFrameIdentifier : int64);
if you use TChromium.RetrieveHTML without parameters you will get the HTML code from the main frame.

You can call TChromium.GetFrameNames or TChromium.GetFrameIdentifiers to get the frame names or identifiers and then call TChromium.RetrieveHTML with one of those names or identifiers to get the HTML code from that frame.
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Get source from an Iframe

Post by thefunkyjoint »

Thank you very much for answering Salvador !

Any examples how to use GetFrameNames ? It has a TStrings parameter, but this is an abstract class...
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get source from an Iframe

Post by salvadordf »

Create a TStringList and use it as the aFrameNames parameter. If necessary cast it as TStrings :

Code: Select all

Chromium1.GetFrameNames(TStrings(MyStringList));
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Get source from an Iframe

Post by thefunkyjoint »

Thank you, this worked. Is there a way to get the frame html source by its id in DOM ?
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Get source from an Iframe

Post by salvadordf »

As far as I know, you can only search by the DOM name. The "identifiers" have nothing to do with the "id" DOM attribute.

Perhaps you can set the focus on some element inside the desired frame and call TChromium.Browser.FocusedFrame
thefunkyjoint
Posts: 460
Joined: Thu Aug 10, 2017 12:40 pm

Re: Get source from an Iframe

Post by thefunkyjoint »

Ok, no problem, the other method worked ! Thanks ! :D
Post Reply