Skip to content Skip to sidebar Skip to footer

How Do I Render Javascript From Another Site, Inside A Php Application?

What I'm trying to do is read a specific line from a webpage from inside of my PHP application. This is my experimental setup thus far:

Solution 1:

cURL does not have a javascript parser. as such, if the content you are trying to read is placed in the page via Javascript after initial page render, then it will not be accesible via cURL.

Solution 2:

The result of the script is supposed executed and return back to your script. PHP doesn't support any feature about web browser itself.

I suggest you try to learn about "web crawler" and "webbrowsers" which are included in .NET framework ( not PHP )

so that you can use the exec() command in php to call it.

try to find out the example code of web crawler and web browsers on codeproject.com

hope it works.

Solution 3:

You can get the entire web page as a file like this:

functionget_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return$data;
}
$returned_content = get_data('http://example.com/page.htm');
$my_file = 'file.htm';
$handle = fopen($my_file, 'w') ordie('Cannot open file: '.$my_file);
fwrite($handle, $returned_content);

Then I suppose you can use a class such as explained in this link below as a guide to separate the javascript from the html (its in the head tags usually). for linked(imported) .js files you would have to repeat the function for those urls, and also for linked/imported css. You can also grab images if you need to save them as files. http://www.digeratimarketing.co.uk/2008/12/16/curl-page-scraping-script/

Post a Comment for "How Do I Render Javascript From Another Site, Inside A Php Application?"