CURL抓取惠民自行车服务点 车辆信息
- /**
- * 惠民自行车服务点 车辆信息
- * @Support:QQ 910111100 (JoY)
- * @Time: 2012.09.29 15:50:00
- * @HZapi.com (http://www.hzapi.com/)
- */
- $url = "http://www.2773456.com/zdfb/huizhou_station.php";
- $ch = curl_init();
- curl_setopt ($ch, CURLOPT_URL, $url);
- curl_setopt ($ch, CURLOPT_REFERER, 'http://www.2773456.com/zdfb/');
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
- curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
- $json = curl_exec($ch);
- //curl_getinfo($ch,CURLINFO_HTTP_CODE); //HTTP状态码(HTTP Status Code)
- curl_close($ch);
- $patterns = array();
- $patterns[0] = '/"s\d{1,3}":/';
- $patterns[1] = '/var area = {/';
- $patterns[2] = '/}}/';
- $patterns[3] = '/},/';
- $patterns[4] = '/\Su/';
- $find = array();
- $find[0] = "";
- $find[1] = "";
- $find[2] = "}";
- $find[3] = "}#";
- $find[4] = "%u";
- $json = preg_replace($patterns, $find, $json); //过滤多余字符
- $json_arr=explode('#',$json); //分割为数组
- $con=count($json_arr);
- /**
- * 模拟JS里的unescape
- *
- * @Support:QQ 910111100 (JoY)
- * @Time: 2012.09.29 15:50:00
- * @HZapi.com (http://www.hzapi.com/)
- */
- //echo unescape('%u4e1c%u6e56%u82b1%u56ed4%u53f7%u5c0f%u533a');
- function unescape($str) {
- $str = rawurldecode($str);
- preg_match_all("/(?:%u.{4})|.{4};|\d+;|.+/U",$str,$r);
- $ar = $r[0];
- #print_r($ar);
- foreach($ar as $k=>$v) {
- if(substr($v,0,2) == "%u")
- {
- $ar[$k] = iconv("UCS-2","GB2312//IGNORE",pack("H4",substr($v,-4)));
- }
- elseif(substr($v,0,3) == "")
- {
- $ar[$k] = iconv("UCS-2","GB2312",pack("H4",substr($v,3,-1)));
- }
- elseif(substr($v,0,2) == "")
- {
- echo substr($v,2,-1)."";
- $ar[$k] = iconv("UCS-2","GB2312",pack("n",substr($v,2,-1)));
- }
- }
- return join("",$ar);
- }
- //循环打印车辆信息
- for($i=0;$i<$con;$i++)
- {
- $ii=$i+1;
- $aa=json_decode($json_arr[$i],true);
- $tr1.="
$ii | ".unescape($aa[QCZZZ])." | ".$aa[CWSZZ]." | ".$aa[DQCSZ]." | ".$aa[kzcs]." | ".$aa[lng]." | ".$aa[lat]." | ".unescape($aa[addr])." | "; - /*echo $aa[FDDMZ]."
"; - echo "站点名称:".unescape($aa[QCZZZ])."
"; - echo "车位总数:".$aa[CWSZZ]."
"; - echo "可借车数:".$aa[DQCSZ]."
"; - echo "空余车位:".$aa[kzcs]."
"; - echo "东京坐标:".$aa[lng]."
"; - echo "北纬坐标:".$aa[lat]."
"; - echo "地址:".unescape($aa[addr])."
"; - echo "==========================================================================
";*/ - }
- ?>
- 惠民自行车服务点 车辆信息
|