Jump to content

Execute javascript when loading web page with file(...url...)


miked2

Recommended Posts

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?

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.