1

When I compare the source code of a webpage in the browser with the source code I get from the code below,

$data = file_get_contents("http://www.someurl.com/loader.aspx");

it differs. The source code is not the same and I suspect that is caused because of some DOM manipulations.

Is it possible to get the HTML source code after the javascript and/or ajax manipulations programmaticly (with PHP)?

MOB
  • 853
  • 2
  • 13
  • 28
  • @jszobody No it doesn't, thanks for the heads up. – Ben Fortune Nov 21 '13 at 16:18
  • i want get the source code of that webpage and save it in varible with php with file-get-contents some html code that generated with js or ajax not recive – MOB Nov 21 '13 at 16:20
  • i want write some php script that's get source code of that site after all js or ajax effect ... – MOB Nov 21 '13 at 16:21
  • @MOB Did you look at my answer? `file_get_contents` will NOT evaluate Javascript code on the page, you have to use a third-party headless browser. – jszobody Nov 21 '13 at 16:23
  • yes ... know see ... can show me some example ... thanx a lot – MOB Nov 21 '13 at 16:24
  • @MOB I included a link to https://github.com/jonnnnyw/php-phantomjs in my answer. All the example code you need is right there. Full instructions. – jszobody Nov 21 '13 at 16:26

1 Answers1

0

You will need to use a headless browser that can evaluate JavaScript on the page. One very popular option is PhantomJS.

Then look at PHP PhantomJS to see how you can control this headless browser from your PHP scripts.

jszobody
  • 28,495
  • 6
  • 61
  • 72
  • unfortunately i cant use PHP PhantomJS for my work ... can help me for use this source and install it when i call PHP PhantomJS below err accourd Fatal error: Class 'JonnyW\PhantomJs\Client' not found in C:\xampp\htdocs\read\test\src\a.php on line 4 – MOB Nov 21 '13 at 21:55