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

查看:49
本文介绍了有没有办法让 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 等待所有动态流量完成?这可能很棘手,因为一些 JavaScript 会不断将数据发送回另一个域,这可能会导致长时间挂起.但至少我可以测试如果我至少得到正确的结果.

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.57 秒内完成.也许我也可以静态告诉 cURL 等待 2 秒?

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 秒,然后要求它为您提供 HTML.

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天全站免登陆