登录  /  注册
博主信息
博文 15
粉丝 0
评论 0
访问量 27092
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
汽车型号json数据(汽车之家)
陈序员的博客
原创
1781人浏览过

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);	
}


本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
1条评论
a梅梅 2020-11-18 14:50:30
$list = file_get_contents('https://www.autohome.com.cn/ashx/AjaxIndexCarFind.ashx?type=1'); $list = json_decode(iconv("GBK", "UTF-8//IGNORE", $list), true); 这两个获取出来都是乱码
1楼
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学