Search code examples
phpsimple-html-dom

How to wait for iFrame to load using PHP Simple DOM Parser


I am using PHP Simple HTML DOM parser to get contents of a web page. I want to traverse an iframe from the page but it seems the iframe is not being captured. It seems the parser completes loading the page before the iframe loads. If I do a var_dump($aside) I get the parsed content, however, a var_dump($iframe) returns NULL. How can I solve this?

$target_url = "https://example.com";
$html = new simple_html_dom();
$html->load_file($target_url);

$aside = $html->find('aside[id=twitter_timeline-2]', 0);
$iframe = $aside->find('iframe[id=twitter-widget-0]', 0);
var_dump($iframe);exit;

Solution

  • you will not see iframe content, you need to get iframe url then download the html