Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the curl library execute javascript inside pages?

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

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.

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);
like image 675
Bob Cavezza Avatar asked Feb 06 '11 07:02

Bob Cavezza


3 Answers

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

like image 137
Oswald Avatar answered Nov 15 '22 22:11

Oswald


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.

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

Browsers have these, but PHP does not.

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

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

like image 43
Haim Evgi Avatar answered Nov 15 '22 20:11

Haim Evgi


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.

like image 27
ayush Avatar answered Nov 15 '22 21:11

ayush