How to use file_get_contents on an Ajax website

When you use file_gets_contents($website) or cURL to download a website, does it download the entire website? I'm most interested in using cURL .

I use it to load a webpage which then receives some content, such as price using AJAX, and it has some problems getting prices.

When I use file_get_contents, it loads, as usual, like the whole site in the browser, plus stuff downloaded with Ajax?

+4
source share
2 answers

No. Using file_get_contents() will only return the contents of the page; it will not execute any JavaScript on the page itself. An analogue of this behavior is almost equivalent to the "View Page Source" in the browser.

+4
source

Excerpt

 $website = 'http://stackoverflow.com/'; file_gets_contents($website) 

loads the result of an HTTP request, nothing more . Thus, the call loads the source of the html page returned by the URL http://stackoverflow.com/ .

In particular, file_gets_contents() does not load the material referenced on the page that http://stackoverflow.com/ points to.

Evaluating JavaScript Code Using PHP

If you want to evaluate JavaScript inside HTML code using a PHP script , you probably want to use the V8 JavaScript engine , which needs to be compiled into your PHP binary:

Find an example of how to use the JavaScript V8 engine here .

0
source

All Articles