微信公众平台开发(63)汽车查询
微信公众平台开发 微信公众平台开发模式 企业微信公众平台 汽车查询
作者:方倍工作室
地址:http://www.cnblogs.com/txw1958/p/weixin-63-coach.html
核心代码:
<?php include('simple_html_dom.php'); // var_dump(getCoachInfo("广州到深圳")); function getCoachInfo($keyword) { $divide = "到"; $dividePos = strpos($keyword, $divide); $divideLen = strlen($divide); $from = substr($keyword, 0, $dividePos); $to = substr($keyword, $dividePos + $divideLen, strlen($keyword) - $dividePos - $divideLen); try { $url = "http://www.keyunzhan.com/zhandaozhan_search.php?find_type=2&shousuo=2&startstate=".urlencode($from)."&endstate=".urlencode($to); $html_coach = file_get_html($url); if (!isset($html_coach)){ $html_coach->clear(); return "检索出错!\n如果经常这样,请发送9到QQ空间给我们留言。"; } $result = ""; foreach($html_coach->find('div[class="car_left_detail01_rows"]') as $singleCoach) { $start = $singleCoach->find('div[class="car_left_detail01_rows_col01"]', 0)->plaintext; $station = $singleCoach->find('div[class="car_left_detail01_rows_col01"]', 1)->plaintext; $end = $singleCoach->find('div[class="car_left_detail01_rows_col01"]', 2)->plaintext; $time = $singleCoach->find('div[class="car_left_detail01_rows_col02"]', 0)->plaintext; $time2 = trim(str_replace("+显示全部", "",$time)); $time3 = preg_replace("/[\n\s]+/is", " ", $time2); $distance = $singleCoach->find('div[class="car_left_detail01_rows_col02"]', 1)->plaintext; $price = $singleCoach->find('div[class="car_left_detail01_rows_col03"]', 0)->plaintext; $result .= "出发:".$start.$station."\n". "目的:".$end."\n". "时间:".$time3."\n". "里程:".$distance."\n". "票价:".$price."\n\n"; } $html_coach->clear(); return trim($result); }catch (Exception $e){ } } ?>
演示图片
欢迎关注方倍工作室微信,了解我们及行业的最新动态
本文来自博客园,作者:方倍工作室,转载请注明原文链接:https://www.cnblogs.com/txw1958/p/weixin-63-coach.html