TA的每日心情 | 无聊 2019-11-23 04:32 |
---|
签到天数: 1 天 [LV.1]初来乍到
- 积分
- 19391
|
马上注册,结交更多淘宝商家,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本篇文漳蘸蘼扣丁书院小编带读者们一路来相识一下PHP爬与天猫战淘宝商品数据的圆法,对PHP开收感爱好的小搭档可以随小编来看一下,文漳蘸蘼中会有代码列出供大家参考,一路来看一下吧。
PHP培训
此外出有多朔怂,大年夜家一路来看一下怎样实现吧:
代码以下:
function crawlUrl($url){
import('PhpQuery.Curl');
$curl=new \Curl();
$result = $curl->read($url);
$content = mb_convert_encoding( $result['content'], 'UTF-8', 'UTF-8,GBK,GB2312,BIG5' );
$myres=array();
if(strrpos($url,'taobao.com')!=false) {
//匹配识恬下架
if(strpos($content,'此宝物已下架')!==false){
return false;
}
preg_match("|itemId : '(.*)'|isU", $content, $match);
$item_id=$match[1];
preg_match("|sellerId : '(.*)'|isU", $content, $match);
$sellet_id=$match[1];
preg_match("|(.*)|isU",$content,$match);
$title=$match[1];
//代卖价库存信息
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'https://detailskip.taobao.com/service/getData/1/p1/item/detail/sib.htm?itemId='.$item_id.'&sellerId='.$sellet_id.'&modules=dynStock,qrcode,viewer,price,duty,xmpPromotion,delivery,upp,activity,fqg,zjys,amountRestriction,couponActivity,soldQuantity,originalPrice,tradeContract&callback=onSibRequestSuccess');
$opt[CURLOPT_HEADER]=false;
$opt[CURLOPT_CONNECTTIMEOUT]=15;
$opt[CURLOPT_TIMEOUT]=300;
$opt[CURLOPT_AUTOREFERER]=true;
$opt[CURLOPT_USERAGENT]='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11';
curl_setopt_array($ch,$opt);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_REFERER,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$out_put=curl_exec ($ch);
curl_close ($ch);
$res=str_replace('onSibRequestSuccess(',"",$out_put);
$res=rtrim($res,');1');
$result=json_decode($res,true);
//查询出图片信息
preg_match('|
|isU', $content, $match);
preg_match_all('/$val){
$nowk=$k;
$nowstore=$val;
break;
}
$myres['title']=str_replace('-tmall.com天猫','',$title);
$myres['price']=$result['defaultModel']['itemPriceResultDO']['priceInfo'][$nowk]['price'];
$myres['act_price']=isset($result['defaultModel']['itemPriceResultDO']['priceInfo'][$nowk]['suggestivePromotionList'])?$result['defaultModel']['itemPriceResultDO']['priceInfo'][$nowk]['suggestivePromotionList']:$result['defaultModel']['itemPriceResultDO']['priceInfo'][$nowk];
$myres['stock']=$result['defaultModel']['inventoryDO']['totalQuantity']?$result['defaultModel']['inventoryDO']['totalQuantity']:$nowstore['quantity'];
//查询出图片信息
preg_match('|
|isU',$content, $match);
preg_match_all('/ |
上一篇:淘宝发布“吃播”数据:美食直播间里三分之二是女吃货下一篇:淘宝数据分析工程师建议:初学大数据,一定要看这套学习路线清单
|