Get Document source After AJAX or js Action With P

2019-08-10 00:03发布

问题:

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)?

回答1:

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.