挖极品 暂停更新及部分源码

wajipin

暂停更新主要是因为淘宝对爬取信息卡得太死了,服务器IP总是被封,导致经常抓取失败,Open API又申请不到,无奈,暂停更新,当年修改主题和开发网站也花了不少时间研究,发点源码中的函数出来,说不定可以帮助一些人。


 

require('Snoopy.class.php');
function snoopyGET($url){
$snoopy = new Snoopy;
$snoopy->agent = "(Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727))"; //伪装浏览器
$snoopy->referer = "http://www.9it.me"; //伪装来源页地址 http_referer
$snoopy->rawheaders["Pragma"] = "no-cache"; //cache 的http头信息
// $snoopy->rawheaders["X_FORWARDED_FOR"] = "8.8.8.101"; //伪装ip
$snoopy->fetch($url); //获取所有内容
return $snoopy->results; //显示结果
}

function getshopitems($theid,$userid){ //利用卖家userid获取店内商品信息
$getitemsurl='https://s.taobao.com/search?inshopn=8&inshops=2&userids='.$userid.'&app=api&m=get_shop_auctions';
//echo $getitemsurl;
// $items=snoopyGET("$getitemsurl");//店内商品信息json
//$items=web_http($getitemsurl,'https',);//店内商品信息json
$items=file_get_contents("$getitemsurl");
if($items=="")
{
$updatelock=0;//解除刷新锁定
update_option( $option_name, $updatelock );
return 0;
}
$itemsUTF8=iconv('GBK', 'UTF-8//IGNORE', $items);
$itemsUTF8 = str_replace('jsonp_reviews_list(','',$itemsUTF8);//去掉多余的字符串
$itemsUTF8 = str_replace(')','',$itemsUTF8);
$itemsdata = json_decode($itemsUTF8,TRUE);//得到数据了,第二个参数是转化为数组
add_post_meta($theid, itemsdata, $itemsdata, true) or update_post_meta($theid, itemsdata, $itemsdata);
}

function trimall($str)//删除空格
{
$qian=array(" "," ","\t","\n","\r");$hou=array("","","","","");
return str_replace($qian,$hou,$str);
}

function cut($file,$from,$end,$num=1){
$message=explode($from,$file);
$message=explode($end,$message[$num]);
return $message[0];
}

function updateshopinfoALL($theid,$shopURL){
//在数据库中添加锁定,防止有人同时刷新页面
$option_name='updatelock';
if(get_option($option_name)==1)return false;//判断下,如果是锁定状态,就不刷新,也不更新时间
$updatelock=1;//开始锁定然后刷新操作
update_option( $option_name, $updatelock );
$time=time();
if($time!="")add_post_meta($theid, updatetime, $time, true) or update_post_meta($theid, updatetime, $time);//第一时间把time更新,防止重复刷新导致被封
//必须要打开店铺一次,否则不知道店铺是否异常,用搜索无法实现

// $ShopContent=snoopyGET("$shopURL");
if(strcmp(substr($shopURL,0,5),"https")!=0)$shopURL="https://".substr($shopURL,7);//如果不是https的自动改为https
$ShopContent=file_get_contents("$shopURL");
if($ShopContent=="")
{
$updatelock=0;//解除刷新锁定
update_option( $option_name, $updatelock );
return 0;
}
$num=1;
if(strpos($ShopContent,iconv('UTF-8', 'GBK', '描述相符'))>0)add_post_meta($theid, shopclose, $num , true) or update_post_meta($theid, shopclose, $num);
if(strpos($ShopContent,iconv('UTF-8', 'GBK', '描述相符'))==false){
$shopclose = get_post_meta($theid, shopclose, true);
$shopclose=$shopclose+1; //如果没有获取到就认为存在异常,终止操作
add_post_meta($theid, shopclose, $shopclose, true) or update_post_meta($theid, shopclose, $shopclose);
$updatelock=0;//解除刷新锁定
update_option( $option_name, $updatelock );
return false;
}
$userid=cut($ShopContent,"userId=", "\"/",1); //未加密的卖家用户ID
$uidjiami=cut($ShopContent,"rate.taobao.com/user-rate-", ".htm",1);
$rateURL="https://rate.taobao.com/user-rate-".$uidjiami.'.htm';
usleep(500000); //延时0.5秒
if($userid!="")getshopitems($theid,$userid); //获取卖家店内商品信息转换为数组后加入数据库
usleep(500000); //延时0.5秒
// $RateContent=snoopyGET("$rateURL");//获取评价页面
//$RateContent=web_http($rateURL,'https','');//获取评价页面
$RateContent=file_get_contents("$rateURL");
if($RateContent=="")
{
$updatelock=0;//解除刷新锁定
update_option( $option_name, $updatelock );
return 0;
}
$RateContentUTF8=iconv('GBK', 'UTF-8//IGNORE', $RateContent);//淘宝是GBK编码的要转换成UTF8
$RateContent=TrimAll($RateContentUTF8,1,3);//去除所有空格
$haopinglv=@cut($RateContent,"<emstyle=\"color:gray;\">好评率:", "</em></h4>",1);
$zhuying=cut($RateContent,".htm\"target=\"_blank\">&nbsp;", "</a>",1);
$shopStartDate=cut($RateContent,"name=\"shopStartDate\"id=\"J_showShopStartDate\"value=\"", "\"/>",1);
$baozhengjin=cut($RateContent,"卖家当前保证金余额<span>¥", "</span>",1);
$wangwang=cut($RateContent,"tbrate.2.1\"data-nick=\"", "\"data-tnick",1);
$wangwangGBK=iconv('UTF-8', 'GBK', $wangwang);
$searchURL="https://s.taobao.com/search?app=shopsearch&rele_field=wangwang&q=".$wangwangGBK;
usleep(500000); //延时0.5秒
// $searchContent=snoopyGET("$searchURL");
$searchContent=file_get_contents("$searchURL");

$searchContentUTF8=iconv('GBK', 'UTF-8//IGNORE', $searchContent);//淘宝是GBK编码的要转换成UTF8
$searchContent=TrimAll($searchContentUTF8,1,3);//去除所有空格
$shopPIC=cut($searchContent,"target=\"_blank\"><imgsrc=\"//", "_70x70.jpg",1); //shopPIC集市和天猫是一样的
$miaoshu=cut($searchContent,"mas\":\"", "\",\"",1); //从店铺搜索找到描述相符分数
$miaoshubijiao=cut($searchContent,"mg\":\"", "%\",\"",1);
$fuwu=cut($searchContent,"sas\":\"", "\",\"",1);
$fuwubijiao=cut($searchContent,"sg\":\"", "%\",\"",1);
$wuliu=cut($searchContent,"cas\":\"", "\",\"",1);
$wuliubijiao=cut($searchContent,"cg\":\"", "%\",\"",1);
if($haopinglv=="") //天猫
{
$leixing="天猫商城";//天猫
}
else //淘宝集市
{
$leixing="淘宝集市";//集市
$sellerxinyong=cut($RateContent,"<li>卖家信用:", "<ahref=\"//",1);
$buyerxinyong=cut($RateContent,"<li>买家信用:", "<",1);
$sellerPic=cut($RateContent,"153-156-164/help-842.htm\"target=\"_blank\"><imgsrc=\"//", "\"border=",1);
}
if($wangwang!="") add_post_meta($theid, wangwang, $wangwang, true) or update_post_meta($theid, wangwang, $wangwang);
if($rateURL!="") add_post_meta($theid, rateURL, $rateURL, true) or update_post_meta($theid, rateURL, $rateURL);
if($shopStartDate!="") add_post_meta($theid, shopStartDate, $shopStartDate, true) or update_post_meta($theid, shopStartDate, $shopStartDate);
if($leixing!="")add_post_meta($theid, leixing, $leixing, true) or update_post_meta($theid, leixing, $leixing);
if($sellerxinyong!="")add_post_meta($theid, sellerxinyong, $sellerxinyong, true) or update_post_meta($theid, sellerxinyong, $sellerxinyong);
if($sellerPic!="")add_post_meta($theid, sellerPic, $sellerPic, true) or update_post_meta($theid, sellerPic, $sellerPic);
if($haopinglv!="")add_post_meta($theid, haopinglv, $haopinglv, true) or update_post_meta($theid, haopinglv, $haopinglv);
if($miaoshu!="")add_post_meta($theid, miaoshu, $miaoshu, true) or update_post_meta($theid, miaoshu, $miaoshu);
if($miaoshubijiao!="")add_post_meta($theid, miaoshubijiao, $miaoshubijiao, true) or update_post_meta($theid, miaoshubijiao, $miaoshubijiao);
if($fuwu!="")add_post_meta($theid, fuwu, $fuwu, true) or update_post_meta($theid, fuwu, $fuwu);
if($fuwubijiao!="")add_post_meta($theid, fuwubijiao, $fuwubijiao, true) or update_post_meta($theid, fuwubijiao, $fuwubijiao);
if($wuliu!="")add_post_meta($theid, wuliu, $wuliu, true) or update_post_meta($theid, wuliu, $wuliu);
if($wuliubijiao!="")add_post_meta($theid, wuliubijiao, $wuliubijiao, true) or update_post_meta($theid, wuliubijiao, $wuliubijiao);
if($shopPIC!="")add_post_meta($theid, shopPIC, $shopPIC, true) or update_post_meta($theid, shopPIC, $shopPIC);
if($zhuying!="")add_post_meta($theid, zhuying, $zhuying, true) or update_post_meta($theid, zhuying, $zhuying);
if($baozhengjin!="")add_post_meta($theid, baozhengjin, $baozhengjin, true) or update_post_meta($theid, baozhengjin, $baozhengjin);
$updatelock=0;//解除刷新锁定
update_option( $option_name, $updatelock );
}