Bob Cavezza
Bob Cavezza

Reputation: 2850

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);

Upvotes: 7

Views: 15419

Answers (3)

Haim Evgi
Haim Evgi

Reputation: 125476

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.

Upvotes: 5

ayush
ayush

Reputation: 14568

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.

Upvotes: 1

Oswald
Oswald

Reputation: 31647

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

Upvotes: 14

Related Questions