帝国cms站群全自动采集入库程序源码分享

研究如何做站群批量采集,下面给大家分享一下自己的代码,如果有技术厉害的大神可以做下优化改进帝国cms自动采集的原创代码:

<?php set_time_limit(0); require("e/class/connect.php"); if(!defined('InEmpireCMS')) { exit(); } /* $loginuserid = getcvar('loginuserid',1); //用户ID $loginusername = getcvar('loginusername',1); //用户名 $loginlevel = getcvar('loginlevel',1); //组ID if($loginuserid!=1 || $loginlevel!=1){ exit('没有操作权限,网站管理员登陆后操作'); } */ //为真输出采集信息,为假发布采集信息 $debug = false; //获取数组给定位置上一个下一个下标 class Steps { private $all; private $count; private $curr; function __construct() { $this->count = 0; } function add($step) { $this->count++; $this->all[$this->count] = $step; } function setCurrent($step) { reset($this->all); for ($i = 1; $i <= $this->count; $i++) { if ($this->all[$i] == $step) break; next($this->all); } $this->curr = current($this->all); } function getCurrent() { return $this->curr; } function getNext() { self::setCurrent($this->curr); return next($this->all); } function getPrev() { self::setCurrent($this->curr); return prev($this->all); } } $cps = array( '全国彩'=>array(//这里的采集地址写完整地址带上http '福彩3d'=>'采集地址1', '福彩双色球'=>'采集地址2', '体彩大乐透'=>'采集地址3', '体彩排列3'=>'采集地址4', '体彩排列5'=>'采集地址5', '体彩七星彩'=>'采集地址6', '福彩七乐彩'=>'采集地址7', ), $czs = array( '福彩3d'=>array('classid'=>3,'titlepic'=>'/skin/images/fcsd.gif'), '福彩双色球'=>array('classid'=>5,'titlepic'=>'/skin/images/fcssq.gif'), '体彩大乐透'=>array('classid'=>6,'titlepic'=>'/skin/images/tcdlt.gif'), '体彩排列3'=>array('classid'=>4,'titlepic'=>'/skin/images/tcp3.gif'), '体彩排列5'=>array('classid'=>77,'titlepic'=>'/skin/images/tcp5.gif'), '体彩七星彩'=>array('classid'=>8,'titlepic'=>'/skin/images/tcqxc.gif'), '福彩七乐彩'=>array('classid'=>7,'titlepic'=>'/skin/images/fcqlc.gif'), ); $sites = array( 'https://www.scw88.com', //可以增加多个网站 但是确保网站后台地址和数据字段一致 ); $area = isset($_GET['a']) ? $_GET['a'] : '全国彩'; $total = isset($_GET['t']) ? $_GET['t'] : 0; $site = isset($_GET['s']) ? $_GET['s'] : 'https://www.scw88.com'; if(empty($site)) exit("采集完毕"); //获取所有地区 $keys = array_keys($cps); //判断地区是否存在 if(!in_array($area,$keys)) die('not found area'); //获取当前地区彩种数量 $area_count = count($cps[$area]); //彩种采集完成跳到下一个地区 if($total==$area_count){ //获取当前区域下标 $area_index = array_keys($keys,$area,true); $steps = new Steps(); foreach($keys as $key=>$value){ $steps->add($key); } $steps->setCurrent($area_index[0]); $next = $steps->getNext(); unset($steps); //获取当前站点下标 $steps = new Steps(); foreach($sites as $key=>$value){ $steps->add($value); } $steps->setCurrent($site); $next_site = $steps->getNext(); if(!$next){ echo('当前:'.$steps->getCurrent().',采集完毕,开始下一个站'); exit("<script>location.href='cj.php?s=$next_site'</script>"); }else{ //获取下一个区域 $next_area = $keys[$next]; //获取下一个地区所有彩种 $next_name_keys = array_keys($cps[$next_area]); //获取下一个地区彩种名称 $next_name = $next_name_keys ? $next_name_keys[0] : ''; exit("<script>location.href='cj.php?next=2&a=$next_area&c=$next_name&t=0&s=$site'</script>"); } } //获取当前地区所有彩种 $name_keys = array_keys($cps[$area]); //获取当前地区彩种名称 $name = $name_keys[$total]; //获取彩种url $url = $cps[$area][$name]; //采集彩种 require_once('curl.class.php'); $curl = new Curl(); $curl->setOpt(CURLOPT_SSL_VERIFYPEER,0); $curl->setOpt(CURLOPT_SSL_VERIFYHOST,0); $curl->get($url); //var_dump($curl); if ($curl->error) { print('error code : '.$curl->error_code .'<br>error message : '. $curl->error_message); //如果超时,刷新页面 if($curl->error_code==7){ exit('<script>location.reload();</script>'); } } //curl返回值为对象 $obj1 = json_encode($curl->response); $obj = json_decode($obj1,TRUE); $html = ""; foreach($obj['result'] as $row){ $html .= '<p name="num">'.str_replace(date('Y',time()),'',$row['issue_no']).'</p>'; $html .= '<p name="qihao">'.$row['issue_no'].'</p>'; $html .= '<p name="kaijiangriqi">'.$row['award_date'].'</p>'; $html .= '<p name="jiangchi">'.$row['pool_amount'].'元</p>'; $html .= '<p name="xiaoshoujine">'.$row['all_amount'].'元</p>'; $objc = json_decode($row['award_count'],TRUE);//print_r($objc); $jiangxiang = '<thead><tr><th>奖项</th><th>中奖注数</th><th>单注金额</th></tr></thead><tbody>'; if(isset($objc['awardinfo'])){ foreach($objc['awardinfo'] as $ainfo){ $jiangxiang .= '<tr><td>'.$ainfo['awards'].'</td><td>'.$ainfo['bet'].'</td><td>'.$ainfo['amount'].'</td></tr>'; } } $jiangxiang .= '</tbody>'; $html .= '<p name="jiangxiang">'.$jiangxiang.'</p>'; $html .= '<p name="hongqiu">'.implode('',array_map(function($obj){return '<span class="num">'.$obj.'</span>';},$row['awardResultList']['redBall'])).'</p>'; $html .= '<p name="langqiu">'.(isset($row['awardResultList']['buleBall']) ? implode('',array_map(function($obj){return '<span class="num blue">'.$obj.'</span>';},$row['awardResultList']['buleBall'])) : '').'</p>'; $html .= '<p name="kaijihao">'.(isset($row['result']) ? implode('',array_map(function($obj){return '<span class="mr-10">'.$obj.'</span>';},explode(',',$row['result']))) : '').'</p>'; $html .= '<p name="shijihao">'.(isset($row['test_result']) ? implode('',array_map(function($obj){return '<span class="mr-10">'.$obj.'</span>';},explode(',',$row['test_result']))) : '').'</p><hr>'; //发布采集结果 if(!$debug){ //下面这里是发布插件 跟火车头发布插件一样的操作 $curl->post($site . '/e/admin/kaijiang.php?pw=123456', array( 'title' => $name.'第'.$row['issue_no'].'期开奖结果', 'ftitle' => $name.$row['issue_no'], 'classid' => isset($czs[$name]['classid']) ? $czs[$name]['classid'] :'', 'kaijihao' => (isset($row['result']) ? implode('',array_map(function($obj){return '<span class="mr-10">'.$obj.'</span>';},explode(',',$row['result']))) : ''), 'kaijiangjieguo' => implode('',array_map(function($obj){return '<span class="num">'.$obj.'</span>';},$row['awardResultList']['redBall'])).(isset($row['awardResultList']['buleBall']) ? implode('',array_map(function($obj){return '<span class="num blue">'.$obj.'</span>';},$row['awardResultList']['buleBall'])) : ''), 'shijihao' => (isset($row['test_result']) ? implode('',array_map(function($obj){return '<span class="mr-10">'.$obj.'</span>';},explode(',',$row['test_result']))) : ''), 'qishuo' => str_replace(date('Y',time()),'',$row['issue_no']), 'benqixiaoliang' => "<b>{$row['all_amount']}元</b>", 'kaijiangshijian' => $row['award_date'], 'benqiqishu' => $row['issue_no'], 'newstext' => $jiangxiang, 'titlepic' => isset($czs[$name]['titlepic']) ? $czs[$name]['titlepic'] :'', 'newstime' => date('Y-m-d H:i:s',time()), 'filepass' => '', 'checked' => 1, 'username' => 'admin', 'ZC'=>get_week($row['award_date']) )); print(strip_tags($curl->response) . '<br>'); } $jiangxiang = ''; } //输出结果 if($debug) echo $html; //下一个彩种 $total = $total+1; echo "<script>location.href='cj.php?next=1&a=$area&c=$name&t=$total&s=$site'</script>"; $curl->close(); ?>

如果使用需要服务器开启curl,全自动运行可以利用宝塔的计划任务来实现,直接保存代码为cj.php,增加URL访问即可,之前说的双彩网走势图功能还在完善中,等完善了会将走势图的一些相关源码放出来供大家学习,关于走势图的美化大家也给提点建议~

原文链接:https://blog.csdn.net/buding888/article/details/121870790?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166669233216782395388777%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=166669233216782395388777&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-30-121870790-null-null.nonecase&utm_term=%E5%B8%9D%E5%9B%BDcms