最新抓取淘宝价格数据,图片标题的就更好抓了整合就好

来源:互联网 发布:端口镜像配置 编辑:程序博客网 时间:2024/06/02 17:59

淘宝现在变成https了。不过难不倒咱们这帮程序员的,不说废话

<?php  $url='https://mdskip.taobao.com/core/initItemDetail.htm?itemId=520048818994';  $ch = curl_init();  curl_setopt($ch, CURLOPT_URL, $url);  //设置来源链接,这里是商品详情页链接  curl_setopt($ch,CURLOPT_REFERER,"https://detail.tmall.com/item.htm?spm=a220m.1000858.1000725.16.e5qIwL&id=520048818994&skuId=3100219519273&areaId=110000&cat_id=2&rn=530571831843b5644f85de9cfa5ee2f3&user_id=2153724245&is_b=1");  curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//规避证书curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 防止302 盗链$result = curl_exec($ch);  curl_close($ch);//去除回车、空格等   $result=str_replace(array("\r\n","\n","\r","\t",chr(9),chr(13)),'',$result); $mode="#([0-9]+)\:#m";  preg_match_all($mode,$result,$s);  $s=$s[1];  if(count($s)>0){  foreach($s as $v){  $result=str_replace($v.':','"'.$v.'":',$result);  }  }  //将字符编码转为utf-8,并且将中文转译,否则json_decode会出现错误   $result=iconv('gb2312','utf-8',$result);  $str=array();  $mode='/([\x80-\xff]*)/i';  if(preg_match_all($mode,$result,$s)){  foreach($s[0] as $v){  if(!empty($v)){  $str[base64_encode($v)]=$v;  $result=str_replace('"'.$v.'"','"'.base64_encode($v).'"',$result);  }  }  }  $result=json_decode($result,true);foreach($result['defaultModel']['itemPriceResultDO']['priceInfo'] as $k=>$v) {if (empty($v['promotionList'])) {$arrprice = $v['price'];} else {$arrprice = $v['promotionList'][0]['price'];}}print_r($arrprice);?>  


0 0
原创粉丝点击