4,249
社区成员




function autonew360buy($arr){
$fucknum=intval($arr['fucknum']); // # 获取抓取条数的整数值
$outime=$fucknum*2+100;
set_time_limit($outime);//设置脚本执行时间
$nextnum=20;//连续查找10次不存在则终止
$sn=$arr['sn'];
while($nextnum>0){
$arr1 = $arr2 = array();
$sn=$sn+1;
$url=$GLOBALS['competitor'][0]['product'].$sn.'.html';
$str =@(file_get_contents($url));
$preg ='/(href="http:\/\/www\.360buy\.com\/brands\/)(\d+)-(\d+)(\.html")/';
$preg2 ='/(href="http:\/\/www\.360buy\.com\/product\/)(\d+)(\.html">)(.*)(<\/a>)/';
$str = iconv("gbk","UTF-8",$str);
preg_match($preg,$str,$arr1);
preg_match($preg2,$str,$arr2);
if(empty($arr1) || empty($arr2)){
$nextnum--;
}else{
$preg='/http\:\/\/price\.360buy\.com\/price-d-(.*)\.html/';
preg_match($preg,$str,$arrp);
$url=$arrp[0];
$str = @(file_get_contents($url));
// $preg='/var jdprice={"P":"\\\uFFE5(\d+)\.(\d+)","I":(\d+)};/';
$preg="/document\.write\('(.*[^\d])(\d+\.\d\d)'\);/";
if(!preg_match($preg,$str,$arrp)){
}else{
// $price=$arrp[1].".".$arrp[2];
$price=$arrp[2];
$autoarr=array('cid'=>$arr1[2],'name_360buy'=>$arr2[4],'price_360buy'=>$price,'sn_360buy'=>$sn);
$this->addnew_360buy($autoarr);
}
$nextnum=20;
$fucknum--;
if($fucknum < 1) return true;
}
}
return true;
}
function autonew360buyAction(){
$jd = new competitor_360buy_site();
if($jd->autonew360buy($_GET)){
echo 'ok';
}else{
echo 'no';
}
//echo $jd->autonew360buy($_GET);
$this->noview();
}
function autonew360buy(obj){
var str = new Object();
if(obj.sn.value.trim()==''){
alert('你必须输入起始的商品序号!');
return false;
}
$('#autonew360buyresult').html('<img src="style/images/loading2.gif"/>');
$('#autonew360buybutton').attr('disabled',true);
str.sn=obj.sn.value;
str.fucknum=obj.fucknum.value;
str.rs = 'newproduct';
str.act = 'autonew360buy';
$.get('index.php',str,function(s){
if(s=='ok'){
$('#result').html('抓取完成!');
}else{
$('#result').html('脚本执行超时导致抓取中断,请刷新页面重新抓取!');
}
$("#result").show(200);
$('#autonew360buyresult').html('');
$('#autonew360buybutton').attr('disabled',false);
});
}