首頁 >後端開發 >php教程 >CURL抓取惠民自行車服務點 車輛訊息

CURL抓取惠民自行車服務點 車輛訊息

WBOY
WBOY原創
2016-07-25 09:02:04936瀏覽
".$aa[DQCSZ]."";
  • /*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])."
    ";
  • 迴音「=========================== ======================= =============================
    ";*/
  • }
  • ?>
  • 複製程式碼
  • CURL抓取惠民自行車服務點車輛訊息
    1. /**
    2. * 惠民自行車服務點車輛資訊
    3. * @Support:QQ 910111100 (JoY)
    4. * @Time: 2012.09.29 15:50:00
    5. * @HZapi.com (http:/ /www.hzapi.com/)
    6. */
    7. $url = "http://www.2773456.com/zdtation/huizhou_ss . php」;
    8. $ch=curl_init();
    9. curl_setopt ($ch, CURLOPT_URL, $url);
    10. curl_setopt($ch, CURLOPT_REFERER, 'http://www.2773456.com/zdfb/zdfb/zd ');
    11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    12. curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (相容; MSIE 6.0; Windows NT 5.1 13); $ch, CURLOPT_CONNECTTIMEOUT,10);
    13. $json =curl_exec($ch);
    14. //curl_getinfo($ch,CURLINFO_HTTP_CODE); //HTTP狀態碼(HTTP Status Code)
    15. $ );
    16. $patterns = array();
    17. $patterns[0] = '/"sd{1,3}":/';
    18. $patterns[1] = '/var區= {/';
    19. $patterns[2] = '/}}/';
    20. $patterns[3] = '/},/';
    21. $patterns[4] = '/Su /' ;
    22. $find = array();
    23. $find[0] = "";
    24. $find[1] = "";
    25. $find[2] = " }" ;
    26. $find[3] = "}#";
    27. $find[4] = "%u";
    28. $json = preg_replace($patterns, $find, $json ); //過濾多餘字元
    29. $json_arr=explode('#',$json); //分割為陣列
    30. $con=count($json_arr);
    31. /**
    32. * 模擬JS裡的unescape
    33. *
    34. * @Support:QQ 910111100 (JoY)
    35. * @Time: 2012.09.29 15:50:00
    36. * @HZapi.com ://www.hzapi.com/)
    37. */
    38. //echo unescape('%u4e1c%u6e56%u82b1%u56ed4%u53f7 %u5c0f%u533a');
    39. function unescape($strstr> );
    40. preg_match_all("/(?:%u.{4})|.{4 };|d+;|.+/U",$str,$r);
    41. $ar = $r[0];
    42. #print_r($ar);
    43. foreach($ar as $k=>$v) {
    44. if(substr($v,0,2) == "% u")
    45. {
    46. $ar[$k] = iconv("UCS- 2","GB2312//忽略",pack("H4",substr($v,-4)));
    47. }
    48. elseif(substr($v,0,3) == "")
    49. {
    50. $ar[$k] = iconv("UCS-2","GB2312",pack( "H4",substr($v,3,-1)));
    51. }
    52. elseif(substr($v,0,2) == "")
    53. {
    54. echo substr($v,2,-1)."";
    55. $ar[$k ] = iconv("UCS-2","GB2312",pack("n",substr($v,2,- 1)));
    56. }
    57. }
    58. return join("", $ar);
    59. }
    60. //循環列印車輛資訊
    61. for($i= 0;$i{
    62. $ii=$ i+1;
    63. $aa=json_decode($json_arr[$i],true);
    64. $tr1. ="
    $ii ".unescape($aa[QCZZZ])." ".$ aa[CWSZZ]."".$aa[kzcs]." ".$aa[lat]." ".unescape($aa[addr])."< ;/td>
    陳述:
    本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn