How to simulate that JavaScript is enabled with PHP Curl?

╄→尐↘猪︶ㄣ 提交于 2020-01-02 15:01:17

问题


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.

Can I enable JavaScript with PHP Curl?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/4258292/how-to-simulate-that-javascript-is-enabled-with-php-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!