当前位置:Gxlcms > PHP教程 > CURL抓取惠民自行车服务点车辆信息

CURL抓取惠民自行车服务点车辆信息

时间:2021-07-01 10:21:17 帮助过:16人阅读

";
  • /*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 "==========================================================================
    ";*/
  • }
  • ?>
    1. 惠民自行车服务点 车辆信息
  • 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/zdfb/huizhou_station.php";
    8. $ch = curl_init();
    9. curl_setopt ($ch, CURLOPT_URL, $url);
    10. curl_setopt ($ch, CURLOPT_REFERER, 'http://www.2773456.com/zdfb/');
    11. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    12. curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
    13. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
    14. $json = curl_exec($ch);
    15. //curl_getinfo($ch,CURLINFO_HTTP_CODE); //HTTP状态码(HTTP Status Code)
    16. curl_close($ch);
    17. $patterns = array();
    18. $patterns[0] = '/"s\d{1,3}":/';
    19. $patterns[1] = '/var area = {/';
    20. $patterns[2] = '/}}/';
    21. $patterns[3] = '/},/';
    22. $patterns[4] = '/\Su/';
    23. $find = array();
    24. $find[0] = "";
    25. $find[1] = "";
    26. $find[2] = "}";
    27. $find[3] = "}#";
    28. $find[4] = "%u";
    29. $json = preg_replace($patterns, $find, $json); //过滤多余字符
    30. $json_arr=explode('#',$json); //分割为数组
    31. $con=count($json_arr);
    32. /**
    33. * 模拟JS里的unescape
    34. *
    35. * @Support:QQ 910111100 (JoY)
    36. * @Time: 2012.09.29 15:50:00
    37. * @HZapi.com (http://www.hzapi.com/)
    38. */
    39. //echo unescape('%u4e1c%u6e56%u82b1%u56ed4%u53f7%u5c0f%u533a');
    40. function unescape($str) {
    41. $str = rawurldecode($str);
    42. preg_match_all("/(?:%u.{4})|.{4};|&#\d+;|.+/U",$str,$r);
    43. $ar = $r[0];
    44. #print_r($ar);
    45. foreach($ar as $k=>$v) {
    46. if(substr($v,0,2) == "%u")
    47. {
    48. $ar[$k] = iconv("UCS-2","GB2312//IGNORE",pack("H4",substr($v,-4)));
    49. }
    50. elseif(substr($v,0,3) == "")
    51. {
    52. $ar[$k] = iconv("UCS-2","GB2312",pack("H4",substr($v,3,-1)));
    53. }
    54. elseif(substr($v,0,2) == "&#")
    55. {
    56. echo substr($v,2,-1)."";
    57. $ar[$k] = iconv("UCS-2","GB2312",pack("n",substr($v,2,-1)));
    58. }
    59. }
    60. return join("",$ar);
    61. }
    62. //循环打印车辆信息
    63. for($i=0;$i<$con;$i++)
    64. {
    65. $ii=$i+1;
    66. $aa=json_decode($json_arr[$i],true);
    67. $tr1.="
    $ii".unescape($aa[QCZZZ])."".$aa[CWSZZ]."".$aa[DQCSZ]."".$aa[kzcs]."".$aa[lng]."".$aa[lat]."".unescape($aa[addr])."
  • 编号站点名称车位总数可借车数空余车位东经坐标北纬坐标地址
  • 人气教程排行