【发布时间】:2018-05-04 16:43:40
【问题描述】:
我正在开发一个每天连接到该站点的功能,以便获取我想要的数据。我想在 html 源中找到与我当前时间相匹配的时间,所以之后我想获取数据。
代码如下:
function get_shows($channel_id, $day, $skip_finished = true)
{
global $day;
$url = 'http://example.com/api/GS?cid=' . $channel_id . '&offset=+00.00&day=' .$day;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_USERAGENT => '',
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5,
CURLOPT_URL => $url,
));
$html = curl_exec($curl);
curl_close($curl);
// create domdocument from html retrieved
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
@$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
}
?>
这是 $html 的输出:
["<a style='width: 149px;' data-time='6:00 pm' <i class=\"c-icon c-8\" >
</i> UEFA Europa League Highlights </h2> <h3>Highlights of all matches in the UEFA Europa League.
<span >7.0</span></h3></a><a style='width: 149px;' data-time='6:30 pm' <h2><i class=\"c-icon c-8\" >
</i> UEFA Europa League Highlights </h2> <h3>Highlights of all matches in the UEFA Europa League.<span >7.0</span></a>"]
如果我当前时间显示为 18:30,我想在 html 源中找到时间 6:30 pm 以匹配或大于它,以便我可以获取以 6:30 pm 开头的数据一直到最后但我不知道该怎么做。
你能告诉我一个例子,我如何使用 $xpath 查询找到时间,以便我可以使用 html 标签获取我想要使用的数据?
编辑:
例如:
如果我的时间显示为下午 6:30,那么我想获取标签以使其显示如下:
6:30 pm
UEFA Europa League Highlights
Highlights of all matches in the UEFA Europa League.
【问题讨论】:
-
我们可以在客户端的javascript中做到这一点吗?