How to simulate that JavaScript is enabled with PHP Curl?
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 wit开发者_Python百科hout JavaScript.
Can I enable JavaScript with PHP Curl?
JavaScript is executed by a browser; cURL does not have a JavaScript parser, therefore can not execute it.
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.
While a TERRIBLE idea: 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.
Read: Parse != Run.
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".
Therefore, if you do NOT have JS enabled, the error won't go away.
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...
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.
For this functionality, you would need a JavaScript engine... to my knowledge there is not one in PHP that is fully functional.
精彩评论