从外部URL获取官方日期和时间

时间:2017-02-23 08:50:46

标签: php simple-html-dom

我正在尝试从外部URL获取正式日期和时间,而我的PHP脚本不会返回我想要的值。你愿意帮我吗?

<?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;
?>

我得到的结果如下: hcentro:fcentro:

无。为什么?我做错了什么?

请帮助我的家伙

1 个答案:

答案 0 :(得分:0)

hcentro div为空:

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

其他div相同。

原因是值是通过javascript创建的。您可能想深入了解javascript代码。

为什么不使用REST service甚至a local public file