如何模拟使用 PHP Curl 启用 JavaScript?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4258292/
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
How to simulate that JavaScript is enabled with PHP Curl?
提问by Felix Grunewald
I want to parse the HTML code from a webpage with PHP Curl, but there is an error msg that I can't access the site without JavaScript.
我想用 PHP Curl 解析网页中的 HTML 代码,但有一个错误消息,我无法在没有 JavaScript 的情况下访问该站点。
Can I enable JavaScript with PHP Curl?
我可以使用 PHP Curl 启用 JavaScript 吗?
回答by simshaun
JavaScript is executed by a browser; cURL does not have a JavaScript parser, therefore can not execute it.
JavaScript 由浏览器执行;cURL 没有 JavaScript 解析器,因此无法执行它。
Because the website is expecting something to tell it that javascript is enabled, you'll need to use a tool that can execute the webpage through an actual browser to give you the html.
因为该网站期待某些东西告诉它启用了 javascript,所以您需要使用可以通过实际浏览器执行网页的工具来为您提供 html。
回答by DampeS8N
While a TERRIBLE idea: http://timwhitlock.info/blog/2008/05/09/full-javascript-parser-for-php/
虽然一个可怕的想法:http: //timwhitlock.info/blog/2008/05/09/full-javascript-parser-for-php/
You could parse the returned string as Javascript. However, you'll run into trouble if it is using AJAX.
您可以将返回的字符串解析为 Javascript。但是,如果它使用 AJAX,您会遇到麻烦。
Read: Parse != Run.
阅读:解析 != 运行。
回答by Aurel Bíly
No.
不。
This is simple like this - a page tests, if you have JavaScript enabled, by using the JavaScript to execute a command, that will remove things like "you don't have JavaScript enabled".
这很简单 - 一个页面测试,如果您启用了 JavaScript,通过使用 JavaScript 执行命令,将删除诸如“您没有启用 JavaScript”之类的内容。
Therefore, if you do NOT have JS enabled, the error won't go away.
因此,如果您没有启用 JS,错误将不会消失。
Optionally (and even more likely) the JavaScript will REDIRECT your browser to the actual page, if JS is not enabled - again, you will stay at the first page, which says you don't have JS enabled...
可选(甚至更有可能)JavaScript 会将您的浏览器重定向到实际页面,如果 JS 未启用 - 同样,您将停留在第一页,这表明您没有启用 JS ......
PHP curlis NOT a full browser. It is just a library that is used for communicatingwith servers, using HTTP, FTP, et cetera. It does not do neither rendering nor parsing.
PHP curl不是一个完整的浏览器。它只是一个用于与服务器通信的库,使用 HTTP、FTP 等。它既不渲染也不解析。
For this functionality, you would need a JavaScript engine... to my knowledge there is not one in PHP that is fully functional.
对于此功能,您需要一个 JavaScript 引擎……据我所知,PHP 中没有一个是全功能的。