CURL抓取惠民自行車服務點車輛訊息
-
/**
- * 惠民自行車服務點車輛資訊
- * @Support:QQ 910111100 (JoY)
- * @Time: 2012.09.29 15:50:00
- * @HZapi.com (http:/ /www.hzapi.com/)
- */
-
- $url = "http://www.2773456.com/zdtation/huizhou_ss . php」;
- $ch=curl_init();
- curl_setopt ($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_REFERER, 'http://www.2773456.com/zdfb/zdfb/zd ');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (相容; MSIE 6.0; Windows NT 5.1 13); $ch, CURLOPT_CONNECTTIMEOUT,10);
- $json =curl_exec($ch);
- //curl_getinfo($ch,CURLINFO_HTTP_CODE); //HTTP狀態碼(HTTP Status Code)
- $ );
-
- $patterns = array();
- $patterns[0] = '/"sd{1,3}":/';
- $patterns[1] = '/var區= {/';
- $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 ://www.hzapi.com/)
- */
- //echo unescape('%u4e1c%u6e56%u82b1%u56ed4%u53f7 %u5c0f%u533a');
- function unescape($strstr> );
- 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//忽略",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{
- $ii=$ i+1;
- $aa=json_decode($json_arr[$i],true);
- $tr1. ="
$ii |
".unescape($aa[QCZZZ])." |
".$ aa[CWSZZ]." | ".$aa[DQCSZ]."".$aa[kzcs]." |
|
".$aa[lat]." |
".unescape($aa[addr])."< ;/td> |
";
- /*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])."
";
- 迴音「=========================== ======================= =============================
";*/
- }
- ?>
-
-
複製程式碼
|