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

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

  12. //取店铺小分类 $shopurl=店铺地址
  13. function ShopType2($shopurl){
  14. $url=file_get_contents($shopurl.'/search.htm?spm=a1z10.5.0.0.PXlPZX&search=y');
  15. //$shoptype='#<i class="cat-icon snd-cat-icon"></i>(.*)<a class="cat-name snd-cat-name"(.*)href="(.*)category-(.*).htm(.*)parentCatId=(.*)\&parentCatName=(.*)"(.*)>(.*)</a>#iUs';
  16. $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';
  17. preg_match_all($shoptype,$url,$type);
  18. for($i=0;$i<count($type[3]);$i++){
  19.     $Tyep2['TypeId'][$i]=$type[5][$i]; //取到小分类ID
  20.     $Tyep2['TypeSId'][$i]=$type[7][$i]; //取到小分类所属的上级分类(大分类ID)
  21.     $Tyep2['TypeName'][$i]=trim($type[10][$i]); //取到小分类名称
  22. }
  23. return $Tyep2;
  24. }

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