有没有办法让cURL等到页面的动态更新完成? [英] Is there a way to let cURL wait until the page's dynamic updates are done?

查看:85
本文介绍了有没有办法让cURL等到页面的动态更新完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中使用cURL提取页面。一切工作正常,但我正在读取页面的一些部分,使用JavaScript计算加载页面后的一小部分。在JavaScript计算完成之前,cURL已经将页面源代码发送回我的PHP脚本,从而导致错误的最终结果。网站上的计算是由AJAX提取的,所以我不能以一种简单的方式重现该计算。此外,我无法访问目标网页的代码,因此我无法调整目标网页以适应我的(cURL)获取需求。

I'm fetching pages with cURL in PHP. Everything works fine, but I'm fetching some parts of the page that are calculated with JavaScript a fraction after the page is loaded. cURL already send the page's source back to my PHP script before the JavaScript calculations are done, thus resulting in wrong end-results. The calculations on the site are fetched by AJAX, so I can't reproduce that calculation in an easy way. Also I have no access to the target-page's code, so I can't tweak that target-page to fit my (cURL) fetching needs.

有任何方式我可以告诉cURL等待所有动态流量完成?这可能是棘手的,由于一些JavaScripts继续发送数据回到另一个域,可能会导致长时间的挂起。但至少我可以测试,如果我至少得到正确的结果。

Is there any way I can tell cURL to wait until all dynamic traffic is finished? It might be tricky, due to some JavaScripts that are keep sending data back to another domain that might result in long hangs. But at least I can test then if I at least get the correct results back.

Safari中的我的开发者工具栏指示页面大约在1.57s。

My Developer toolbar in Safari indicates the page is done in about 1.57s. Maybe I can tell cURL statically to wait for 2 seconds too?

我不知道有什么可能性:)

I wonder what the possibilities are :)

推荐答案

cURL不执行任何JavaScript或下载文档中引用的任何文件。所以cURL不是你的问题的解决方案。

cURL does not execute any JavaScript or download any files referenced in the document. So cURL is not the solution for your problem.

你必须在服务器端使用浏览器,告诉它加载页面,等待X秒,

You'll have to use a browser on the server side, tell it to load the page, wait for X seconds and then ask it to give you the HTML.

查看: http:/ /phantomjs.org/ (您需要使用node.js,我不知道任何PHP解决方案)。

Look at: http://phantomjs.org/ (you'll need to use node.js, I'm not aware of any PHP solutions).

这篇关于有没有办法让cURL等到页面的动态更新完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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