0

I am trying to get the Official Date and Time from an external URL and my PHP script does not return the values I want. Would you be so kind as to help me please?

<?php
// example of how to use basic selector to retrieve HTML contents
require_once('simplehtmldom/simple_html_dom.php');

// get DOM from URL or file
$html = file_get_html('http://www.cenam.mx/hora_oficial/');

// get and show the Mexico Center's Time
$hcentro = $html->find('div[id=hcentro]', 0)->innertext;
echo 'hcentro: '. $hcentro;

// get and show the Mexico Center's Date 
$fcentro = $html->find('div[id=fcentro]', 0)->innertext;
echo 'fcentro: '. $fcentro;
?>

The result I get simply is the following: hcentro: fcentro:

Nothing. Why? What am I doing wrong?

Please Help Me Guys

1 Answers1

0

The hcentro div is empty:

Tiempo del Centro</strong> 
<div style="FONT-SIZE: 15pt;font-weight: bold; FONT-FAMILY: Times New Roman;  " id="hcentro">
</div>

Same for the other div.

The reason is the values are created via javascript. You might want to dig deeper into the javascript code.

Why don't you use a REST service or even a local public file

Community
  • 1
  • 1
Laur Ivan
  • 4,117
  • 3
  • 38
  • 62