curl 库是否在页面内执行 javascript?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4912257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 15:20:57  来源:igfitidea点击:

Does the curl library execute javascript inside pages?

phpjavascriptcurl

提问by Bob Cavezza

I'm working with a few pages where javascript executes form submission on page load.

我正在处理几个页面,其中 javascript 在页面加载时执行表单提交。

Does the curl library automatically execute javascript in web pages? If it does, is there a way to return the changed DOM instead of the default one that I'm returning with simple curl code.

curl 库会自动在网页中执行javascript吗?如果是这样,有没有办法返回更改后的 DOM,而不是我用简单的 curl 代码返回的默认值。

Here's my currentcode:

这是我的当前代码:

    $curl_handle=curl_init();
    curl_setopt($curl_handle,CURLOPT_URL,$url);
    $buffer = curl_exec_follow($curl_handle,10);        
    curl_setopt($curl_handle,CURLOPT_HEADER, 0);
    curl_setopt($curl_handle,CURLOPT_FOLLOWLOCATION, 1); 
    $buffer = curl_exec($curl_handle);

回答by Oswald

No, it does not. It does not apply css styles either.

不,不是的。它也不适用 css 样式。

回答by Haim Evgi

No. A web page with embedded JavaScript is actually a program. CURL gives you the program's source code (HTML and JavaScript), but doesn't run that program.

没有。嵌入 JavaScript 的网页实际上是一个程序。CURL 为您提供程序的源代码(HTML 和 JavaScript),但不运行该程序。

To run a page's embedded JavaScript you need (1) a JavaScript interpreter, and (2) the Document Object Model (DOM) for the page.

要运行页面的嵌入式 JavaScript,您需要 (1) 一个 JavaScript 解释器,以及 (2) 页面的文档对象模型 (DOM)。

Browsers have these, but PHP does not.

浏览器有这些,但PHP 没有

People are working on PHP versions of these, but developing these are big tasks.

人们正在研究这些的 PHP 版本,但开发这些是一项艰巨的任务。

If this is what you need, you might skip PHP and instead look at writing C++ code using WebKit.

如果这是您的需要,您可以跳过 PHP,转而使用 WebKit 编写 C++ 代码。

回答by ayush

PHP curl is NOT a full browser. It is just a library that is used for communicating with servers, using HTTP, FTP, et cetera. It does not do neither rendering nor parsing.

PHP curl 不是一个完整的浏览器。它只是一个用于与服务器通信的库,使用 HTTP、FTP 等。它既不渲染也不解析。