-1

with the following code I can get the html content of another page. This works really good:

<?php
$html = file_get_contents('XXX');
$dom = new DOMDocument();
$dom->loadHTML($html);
echo $html;
?>

But I have some results on the other page, which will loaded with a litte delay (some javascript will show this results) and my file_get_contents will only get the html content without this javascript results.

is there an way to call my other page, wait a little bit and get the content after the other site will completely loaded?

Trombone0904
  • 4,132
  • 8
  • 51
  • 104
  • JavaScript is executed in browser, but `file_get_contents` will only get source code without executing JavaScript. – lolbas Feb 02 '18 at 07:57
  • No, not unless you run a javascript interpreter on your server. – KIKO Software Feb 02 '18 at 07:58
  • Possible duplicate of [Get the content (text) of an URL after Javascript has run with PHP](https://stackoverflow.com/questions/28505501/get-the-content-text-of-an-url-after-javascript-has-run-with-php) – lolbas Feb 02 '18 at 08:00

1 Answers1

0

Create an iframe

<iframe src="" id="myframe"></iframe>

Then assign it's src attribute with jQuery

$(document).ready(function(){
  $('#myframe').attr('src','your/url');
});

You can also set delay with

$(document).ready(function(){
  setTimeout(function(){
      $('#myframe').attr('src','your/url');
  },5000);
});
Albert Einstein
  • 7,472
  • 8
  • 36
  • 71
Güney Saramalı
  • 791
  • 1
  • 10
  • 19
  • with this code, I get these errors in my console: `Unrecognized Content-Security-Policy directive 'reflected-xss'.` AND `Refused to display 'MY_URL' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.` – Trombone0904 Feb 02 '18 at 08:50
  • what did you write into 'your/url' section? @Ghost108 – Güney Saramalı Feb 02 '18 at 08:52
  • The problem is this. Some of the webpages are blocking their content to be taken by other websites with iframe. This example works for this page but when you change the url for ex: google, it blocks and gives error. @Ghost108 http://cr8code.co/editor.php?workid=7dd4870ba5f1d7fb175054033194e61f – Güney Saramalı Feb 02 '18 at 09:03
  • yes, this is should be the problem. I guess the other side will block it. is there another way? – Trombone0904 Feb 02 '18 at 09:24
  • I think not and the other PHP solution is only get html i belive. – Güney Saramalı Feb 02 '18 at 09:54