开发了酷讯-Kuxun的火车时刻表采集程序PHP接口
Kuxun的车次使用Json编码,火车采集时,直接采集车次就行,这个接口可以把车站、里程、价格等信息处理成表格形式,方便处理。
火车采集器标准版用户可以直接使用,其它程序的用户可以改改PHP代码运行。
[php]
<?php
/*
* 火车采集器内置接口 For Kuxun 车次采集,输出数据为表格
* 本文件请以UTF-8编码存放于火车采集器 interface 目录下。
*
* By 尘缘 QQ:133775 2009年11月8日
*
* */
error_reporting(7);
/* 车次 */
$id = $LabelArray[‘简介’];
/* 查询结果地址 */
$url = "http://daohang.skb.kuxun.cn/traindetailinfo.php?id={$id}";
/* 获取数据 */
$content = @file_get_contents($url);
!trim($content) && exit;
/* 火车采集器2009 SP4 以上即支持 Json */
$content = @json_decode($content);
//print_r($content);
$seattypes = explode(‘,’,$content->seattypes);
foreach ($content->stations as $key=>$station){
$stationid = $key + 1;
$pricelist = "";
$distance = $station->distance;
$runtime = $station->runtime;
foreach ($seattypes as $type){
switch ($type){
case ‘yz’:
$price = $station->price->yz;
break;
case ‘rz’:
$price = $station->price->rz;
break;
case ‘yw’:
$price = $station->price->ywx;
break;
case ‘rw’:
$price = $station->price->rwx;
break;
case ‘ydz’:
$price = $station->price->ydz;
break;
case ‘edz’:
$price = $station->price->edz;
break;
default:
$price = 0;
}
$pricelist .= " <td>{$price}元</td>\n";
}
$me .= "<tr>
<td>{$stationid}</td>
<td>{$id}</td>
<td>{$station->name}</td>
<td>{$station->arrivaltime}</td>
<td>{$station->departtime}</td>
<td>{$station->staytime}</td>
<td>{$station->runtime}</td>
<td>{$station->distance}公里</td>
{$pricelist}
</tr>\n";
}
/* 生成座位类型 */
function getSeattype($type){
$seattypes = array( "yz"=>"硬座",
"rz"=>"软座",
"yw"=>"硬卧",
"yws"=>"硬卧上",
"ywz"=>"硬卧中",
"ywx"=>"硬卧下",
"rw"=>"软卧",
"rws"=>"软卧上",
"rwx"=>"软卧下",
"ydz"=>"一等座",
"edz"=>"二等座"
);
return $seattypes[$type];
}
/* 根据座位类型生成表格 */
function getInfo($id, $seattypes, $body, $distance, $runtime){
foreach ($seattypes as $value){
$value = getSeattype($value);
$seattype .= "<th align=’left’>$value</th>\r\n";
}
return $body = "<table cellspacing=’0′ cellpadding=’0′ width=’100%’>
<tbody>
<tr>
<td bgcolor=’#eff8ff’ colspan=’11’><div>
<table border=’0′ cellspacing=’0′ cellpadding=’0′ width=’100%’>
<tbody>
<tr>
<td colspan=’6′>车次:<strong>{$id}</strong>(全程:{$distance}公里)</td>
<td colspan=’2′></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<th align=’left’>站次</th>
<th align=’left’>车次</th>
<th align=’left’>站名</th>
<th align=’left’>到达时间</th>
<th align=’left’>开车时间</th>
<th align=’left’>停留</th>
<th align=’left’>运行时间</th>
<th align=’left’>里程</th>
{$seattype}
</tr>
{$body}
<tr>
<th colspan=’6′>区间:{$distance}公里</th>
<th colspan=’4′>全程:{$runtime}</th>
</tr>
</tbody>
</table>";
}
$LabelArray[‘简介’] = getInfo($id, $seattypes, $me, $distance, $runtime);
//#############以上为用户操作区域#############
//#############以下语句必须保留,建议不更改######
//ob_clean();
echo serialize($LabelArray);
?>
[/php]
接口下载:酷讯采集程序