php爬取第三方接口get请求
2021/7/17 11:35:05
本文主要是介绍php爬取第三方接口get请求,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
爬数组
$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);
这篇关于php爬取第三方接口get请求的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23怎么实现安卓+php 热更新方案?-icode9专业技术文章分享
- 2024-11-22PHP 中怎么实现判断多个值是否为空、null 或者为 false?-icode9专业技术文章分享
- 2024-11-11开源 PHP 商城项目 CRMEB 二次开发和部署教程
- 2024-11-09怎么使用php在kaufland平台刊登商品?-icode9专业技术文章分享
- 2024-11-05PHP的抽象类和接口是什么,有什么区别-icode9专业技术文章分享
- 2024-11-01开源 PHP 商城项目 CRMEB 安装和使用教程
- 2024-11-01用php和mysql写无限分类,有哪几种方法-icode9专业技术文章分享
- 2024-10-31php数据分表导出时部分数据无法导出什么原因-icode9专业技术文章分享
- 2024-10-30有经验的 PHP 开发者学习一门新的编程语言,有哪些推荐的有前景的语言-icode9专业技术文章分享
- 2024-10-21php 检测图片是否篡改过-icode9专业技术文章分享