miked2 Posted June 30, 2008 Share Posted June 30, 2008 I have a php program that gets statistics from a router. Now that I have a new router, the program has to deal with JavaScript. The web page has fields that look like: <td...> </td> and the is replaced when the page is loaded into the browser by some values from JavaScript code. When I grab the page with php: $statusUrl = "http://..."; //valid URL for router info page $statusPage = file($statusUrl); I get the and not the JavaScript-provided data, since the JS is not executed. Is there a way to get the JS to execute so that the values are filled in? Does PHP have such capability? Link to comment https://forums.phpfreaks.com/topic/112528-execute-javascript-when-loading-web-page-with-fileurl/ Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 you've lost me, and probably many other PHP Freaks, what are you exactly talking about? Link to comment https://forums.phpfreaks.com/topic/112528-execute-javascript-when-loading-web-page-with-fileurl/#findComment-577852 Share on other sites More sharing options...
miked2 Posted June 30, 2008 Author Share Posted June 30, 2008 PHP lets one grab a web page and look at it. So I specify the web page with: [pre]$statusUrl = "http://..."; // ... = valid URL for router info page[/pre] and load it into my PHP program with: [pre]$statusPage = file($statusUrl);[/pre] Now I can loop through the page and look at the content: [pre] $lines = array_map('rtrim', $statusPage ); // Find <h2>WAN</h2> first. This is the start of the interesting block. $foundWan = false; foreach ($lines as $line_num => $line) { if( strpos( $line, "<h2>WAN</h2>" ) !== false ) { $foundWan = true; break; } } // ... now look at the content of the WAN box... ...[/pre] However, when I look at the content of the page, I see text like: [pre]<td...> </td>[/pre] rather than what's seen on the web page (e.g.): [pre]<td...>175MB</td>[/pre] The difference is that when the web page is shown on a browser, JavaScript code will load the data by replacing the with data such as 175MB. So - the browser executes the JavaScript, but when the page is loaded into my PHP program, the JavaScript does not appear to have been executed, hence the lack of data in the HTML. It's as if the PHP web page load is only getting the text but does not actually act like a web browser to complete the page by executing all the onload JavaScript. Is there a way to get PHP to do this? A parameter or different function other than file(...)? Or do I need to somehow run some kind of JavaScript preprocessor? Or is this just not possible? Link to comment https://forums.phpfreaks.com/topic/112528-execute-javascript-when-loading-web-page-with-fileurl/#findComment-578374 Share on other sites More sharing options...
PFMaBiSmAd Posted June 30, 2008 Share Posted June 30, 2008 The easiest solution would be for you to examine the javascript code and then request/read the data from where the javascript is getting it. Link to comment https://forums.phpfreaks.com/topic/112528-execute-javascript-when-loading-web-page-with-fileurl/#findComment-578379 Share on other sites More sharing options...
miked2 Posted July 1, 2008 Author Share Posted July 1, 2008 Well, I'd have to say - Duh, why didn't I think of that! It took a while to find it, but it turns out the data is supplied as xml stuff and is easier to parse once loaded into my PHP program. Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/112528-execute-javascript-when-loading-web-page-with-fileurl/#findComment-579231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.