dd

PHP采集淘宝的店铺的大小分类

jerry thinkphp 2015年11月19日 收藏
PHP采集淘宝的店铺的大小分类
//取店铺大分类 $shopurl=店铺地址
function ShopType1($shopurl){
$url=file_get_contents($shopurl.'/search.htm?spm=a1z10.5.0.0.PXlPZX&search=y');
$shoptype='#<i class="cat-icon fst-cat-icon  active-trigger"></i>(.*)<a class="cat-name fst-cat-name"(.*)href="(.*)category-(.*).htm(.*)"(.*)>(.*)</a>#iUs';
preg_match_all($shoptype,$url,$type);
for($i=0;$i<count($type[3]);$i++){
    $Tyep1['TypeId'][$i]=$type[4][$i]; //取到大分类ID号
    $Tyep1['TypeName'][$i]=trim($type[7][$i]); //取到大分类名称
}
return $Tyep1;
}

//取店铺小分类 $shopurl=店铺地址
function ShopType2($shopurl){
$url=file_get_contents($shopurl.'/search.htm?spm=a1z10.5.0.0.PXlPZX&search=y');
//$shoptype='#<i class="cat-icon snd-cat-icon"></i>(.*)<a class="cat-name snd-cat-name"(.*)href="(.*)category-(.*).htm(.*)parentCatId=(.*)\&parentCatName=(.*)"(.*)>(.*)</a>#iUs';
$shoptype='#<h4 class="cat-hd snd-cat-hd" data-cat-id="(.*)">(.*)<i class="cat-icon snd-cat-icon"></i><a class="cat-name snd-cat-name"(.*)href="(.*)category-(.*).htm(.*)parentCatId=(.*)\&parentCatName=(.*)"(.*)>(.*)</a>(.*)</h4>#iUs';
preg_match_all($shoptype,$url,$type);
for($i=0;$i<count($type[3]);$i++){
    $Tyep2['TypeId'][$i]=$type[5][$i]; //取到小分类ID
    $Tyep2['TypeSId'][$i]=$type[7][$i]; //取到小分类所属的上级分类(大分类ID)
    $Tyep2['TypeName'][$i]=trim($type[10][$i]); //取到小分类名称
}
return $Tyep2;
}

//淘宝分类地址 http://店铺域名/category-(分类的ID号,大小分类都一样).htm
//其他采集处理就由你们自己去动动脑子吧, 这是我一个朋友做SDK模板让我帮他写的
dd