使用PHP进行AJAX或js操作后获取文档源 [英] Get Document source After AJAX or js Action With PHP

查看:77
本文介绍了使用PHP进行AJAX或js操作后获取文档源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将浏览器中网页的源代码与从下面的代码中获得的源代码进行比较时,

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");

这是不同的。源代码不同,我怀疑这是由于某些DOM操作引起的。

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

是否有可能在javascript和/或ajax之后获取HTML源代码

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

推荐答案

您将需要使用无头浏览器来评估页面上的JavaScript。一个非常受欢迎的选项是 PhantomJS

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

然后看一下< a href = https://github.com/jonnnnyw/php-phantomjs rel = nofollow> PHP PhantomJS ,了解如何从PHP脚本控制此无头浏览器。

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

这篇关于使用PHP进行AJAX或js操作后获取文档源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆