skos
skos

Reputation: 4222

PHP: Getting Final Rendered HTML of a Remote Site

Lets say there's a HTML page with following code in it -

<body>
  <div id='some_id'></div>
  <script>
     var div = document.getElementById("some_id");
     var input = document.createElement("input");
     input.type="text";     
     input.value="text box";
     div.appendChild(input); 
 </script>
</body>

Now if I do View-source, I will see this above code. But If I use a firebug, I will see this -

<body>
  <div id='some_id'><input type="text"></div>
  <script>
     var div = document.getElementById("some_id");
     var input = document.createElement("input");
     input.type="text";     
     input.value="text box";
     div.appendChild(input); 
 </script>
</body>

That is, the final rendered HTML output is different. Lets assume this file is on another server like - http://www.someanotherserver.com/some_file.html

Now is it possible in PHP to get the final rendered HTML output ? file_get_contents I guess will just show what I see in view-source.

Upvotes: 2

Views: 1528

Answers (1)

Ayush
Ayush

Reputation: 42450

Using PHP, no there is no way you can get the final rendered HTML. This is because the changes made to the original source code are done when the javascript executes. This requires you to have a Javascript engine/runtime (your browser has one).

Doing file_get_contents() is the same as doing curl or wget - it queries the server, but does not execute any JS.

Upvotes: 2

Related Questions