AUTOHOME的
http://www.autohome.com.cn/ashx/AjaxIndexCarFind.ashx?type=1
或者
http://www.autohome.com.cn/ashx/AjaxIndexCarFind.ashx?type=11
获取***列表,然后
http://www.autohome.com.cn//ashx/AjaxIndexCarFind.ashx?type=3&value=3
获取车型列表(例子中的value=3对应丰田)。
生成json代码:
public function setCarJson() { ini_set('max_execution_time', '0'); $carJson = array(); $list = file_get_contents('https://www.autohome.com.cn/ashx/AjaxIndexCarFind.ashx?type=1'); $list = json_decode(iconv("GBK", "UTF-8//IGNORE", $list),true); if($list['message'] == '成功'){ $pingpai = $list['result']['branditems']; foreach($pingpai as $k=>$v){ //判断数组中是否包含A,B键 if(!isset($carJson[$v['bfirstletter']])){ $carJson[$v['bfirstletter']] = []; } $newArr = ['city'=>['name'=>$v['name'],'code'=>$v['id'],'areaList'=>[]]]; $url = 'https://www.autohome.com.cn//ashx/AjaxIndexCarFind.ashx?type=3&value='.$v['id']; $list1 = file_get_contents($url); $list1 = json_decode(iconv("GBK", "UTF-8//IGNORE", $list1),true); if($list1['message'] == '成功' && isset($list1['result']['factoryitems'][0]['seriesitems'])){ $chexing = $list1['result']['factoryitems'][0]['seriesitems']; foreach($chexing as $kk=>$vv){ array_push($newArr['city']['areaList'],['name'=>$vv['name'],'code'=>$vv['id']]); } } array_push($carJson[$v['bfirstletter']], $newArr); unset($newArr); } } dump(json_encode($carJson,JSON_UNESCAPED_UNICODE)); // dump($newArr); }