爬数组
$str='https://www.changjingdian.com/api/dynamic/DescribeDynamicForBusinessByPage?appSecret=saishangcff8d98e662d47ab98d23cb2041ee2d9'; $data=file_get_contents($str); $data=json_decode($data,true); dd($data); // $data=[]; $en=[]; foreach($data['data']['list']as $k =>$val){ // $en[$k]['id']=isset($val['id']) ?$val['id'] : ''; // $en[$k]['dynamicId']=isset($val['dynamicId']) ?$val['dynamicId'] : ''; $en[$k]['coverImage']=isset($val['coverImage']) ?$val['coverImage'] : ''; $en[$k]['coverImageWidth']=isset($val['coverImageWidth']) ?$val['coverImageWidth'] : ''; $en[$k]['coverImageHeight']=isset($val['coverImageHeight']) ?$val['coverImageHeight'] : ''; $en[$k]['type']=isset($val['type']) ?$val['type'] : 0; $en[$k]['creatorUserName']=isset($val['creatorUserName']) ?$val['creatorUserName'] : ''; $en[$k]['creatorPhone']=isset($val['creatorPhone']) ?$val['creatorPhone'] : ''; $en[$k]['storeId']=isset($val['storeId']) ?$val['storeId'] : ''; $en[$k]['storeUserId']=isset($val['storeUserId']) ?$val['storeUserId'] : ''; $en[$k]['createTime']=isset($val['createTime']) ?$val['createTime'] : ''; } // User::query()->insert($en); DB::table('zz')->insert($en); //dd($en);
爬对象 就是单值 如果爬行的单值是数组 记得用json_encode转换
$str='https://www.changjingdian.com/api/dynamic/DescribeDynamicInfo?appSecret=saishangcff8d98e662d47ab98d23cb2041ee2d9&dynamicId=22360'; $data=file_get_contents($str); $data=json_decode($data,true); // dd($data['data']['dynamicForBusinessView']); //$data=[]; $s=$data['data']['dynamicForBusinessView']; //dd($s); $en=[]; // $en[$k]['id']=isset($val['id']) ?$val['id'] : ''; $en['dynamicId']=isset($val['dynamicId']) ?$s['dynamicId'] : 0; $en['coverImage']=isset($s['coverImage']) ?$s['coverImage'] : ''; $en['coverImageWidth']=isset($s['coverImageWidth']) ?$s['coverImageWidth'] : ''; $en['coverImageHeight']=isset($s['coverImageHeight']) ?$s['coverImageHeight'] : ''; $en['resourceUrls']=isset($s['resourceUrls']) ?json_encode($s['resourceUrls']): ''; $en['type']=isset($s['type']) ?$s['type'] : 0; $en['creatorUserName']=isset($s['creatorUserName']) ?$s['creatorUserName'] : ''; $en['creatorPhone']=isset($s['creatorPhone']) ?$s['creatorPhone'] : ''; $en['storeId']=isset($s['storeId']) ?$s['storeId'] : ''; $en['storeUserId']=isset($s['storeUserId']) ?$s['storeUserId'] : ''; $en['createTime']=isset($s['createTime']) ?$s['createTime'] : ''; // User::query()->insert($en); DB::table('bb')->insert($en); dd($en);