search
Homephp教程PHP源码skymvc网站测试之页面测试,爬行所有页面

跳至 [1] [全屏预览]
<?php
/******
*Author 雷日锦
*本代码在skymvc中使用 http://www.skymvc.com
*页面测试 自动爬行所有页面
*******/
class test_pageControl extends skymvc{
	
	public $para=array("id","catid","userid");
	public $action=array("default","list","show","add","my");
	public $id=123;
	public $per_page=1;
	public $maxThreads=10;
	public $token="1234";
	public $site="http://skymvc.skymvc.com/index.php?";
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
		
	}
	
	public function getTables(){
		$res=M("article")->query("show tables");
		$data=M("article")->fetch_array(PDO::FETCH_NUM);
		foreach($data as $k=>$t){
			$tables[]=str_replace(TABLE_PRE,"",$t[0]);
		}
		return $tables;
	}
	
	public function onSetAction($a=array()){
		 
		if(!empty($a)){
			$this->action=array_merge($this->action,$a);
		}		
		 

	}
	public function onSetPara($a=array()){
		 
		if(!empty($a)){
			$this->para=array_merge($this->para,$a);
		}		
	 
	}
	
	public function getUrls(){
		$tables=$this->getTables();
		$para="";
		foreach($this->para as $q){
			$para.="&$q=".$this->id;
		}
		$para.="&token=".$this->token."&per_page=".$this->per_page;
		foreach($tables as $m){
			$uk=0;
			foreach($this->action as $k=>$a){
				$urls[]=$this->site."m=$m&a=$a".$para;
				if($k%$this->maxThreads==($this->maxThreads-1)){
					$uk++;
				}
			}
		}
		return $urls;
	}
	 
	public function onStart(){
		set_time_limit(0);
		ob_implicit_flush(true);
		$urls=$this->getUrls();
		$uk=0;
		foreach($urls as $k=>$url){
			$purls[$uk][]=$url;
			if($k%$this->maxThreads==($this->maxThreads-1)){
				$uk++;
			}
		}
		echo "开始<br>";
		foreach($purls as $k=>$urls){
			echo "第".$k."部分<br>";
			flush();
			@ob_flush();
			$this->loadClass("spider");
			$this->spider->start($urls,function($data){
				echo $data['url']." <br>";
				flush();
				@ob_flush();
			});
		}
		echo "测试结束";
	}
	
}

?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.