Home > php教程 > php手册 > body text

原创php采集器 v1.02

WBOY
Release: 2016-06-06 19:37:33
Original
1208 people have browsed it

用于网站采集,使用简单:支持分页采集、图片下载、过滤等,说明不多,仅限于php的二次开发,之前的代码片段先删除,请直接下载附件,如需要采集服务可联系我 PHP ?php/** * 抓取器 * @author Administrator * @example $config = array( * 'host'='服务器地

用于网站采集,使用简单:支持分页采集、图片下载、过滤等,说明不多,仅限于php的二次开发,之前的代码片段先删除,请直接下载附件,如需要采集服务可联系我
PHP
<?php
/**
 * 抓取器
 * @author Administrator
 * @example $config = array(
 * 		'host'=>'服务器地址',
 * 		'list'=>array(
 * 			'items'=>array(正则表达式组),
 * 			'page_url'=>'分页地址正则表达式,$1为链接,$2显示的数字',
 * 			'page_size'=>'分页大小',
 * 			'page_url_rule'=>'获取页码数的正则,$1必为数字',
 * 			'page_limit'=>数字,要扫描的最大页数,如果不填,则只扫描可视范的页码数
 * 			'this_detail_callback'=>'对详情页的数据执行回调函数',
 * 			'list_detail_url'=>'指定list中的items中名称为详情页的地址'
 * 		)
 *
 * 		details=>array(
 * 			详情页的所有规则,见items结构说明
 * 		),
 *
 * 		time_limit=>array('rule'=>对应的组名,start=>超始时间,end=>结束时间),
 * 		num_limit=>获取多少条数据
 * )
 *
 * items结构解析: array(
 * 		'属性名称'=>array('rule'=>正则表达式,多种情况时为数组,type=>' 1-文本,2-远程请求,3->'子规则列表items',4=>'子config配置',
 * 	replace=>替换结果,以回调函数形式或采用数组array(from=>'正则表达式','to'=>替换字符),'multi'=>是否采集多条数据),
 * )
 */

set_time_limit(0);
define('IN_WEB',true);
date_default_timezone_set('PRC');
include('collector/init.php');

$htmlFilter = '/<link[^>]*\/>|((onclick|onmouseover|onmouseout|onblur)=\"[^\"]+\")|<!--(.+?)-->|<div[^>]*>|<\/div>|<style[^>]*>(.+?)<\/style>|<embed[^>]*>(.+?)<\/emded>|<object[^>]*>(.+?)<\/object>|<script[^>]*>(.*?)<\/script>|<noscript[^>]*>(.+?)<\/noscript>|<a[^>]*>|<\/a>/is';
$config = array(
		'host'=>'http://news.wto168.net/zixun/',
		'list'=>array(
				'items'=>array(
						'time'=>array('rule'=>'/>.*([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}\s*[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})<\/li>/i','multi'=>true),
						'link'=>array('rule'=>'/<a href=\"([^\"]+)\" class=\"title\">/i','multi'=>true, ),
						'title'=>array('rule'=>'/<a href=\"[^\"]+\" class=\"title\">([^>]+)<\/a>/i','multi'=>true,'replace'=>array('from'=>'/【.+】/','to'=>'')),
				),

				'list_detail_url'=>'link',

				'page_url'=>'/<option value=\'(list_56_(\d+)\.html)\'[^>]*>\d+<\/option>/i',
				'page_url_rule'=>'/_(\d+)\.html/',
				'page_limit'=>10,
		),
		'details'=>array(
				'content'=>array('rule'=>'/<div id=\"wto168NewsContent\">(.+?)<div style=\"width:664px; padding-left:0px; padding-right:15px;\">/is',
						'keep_html'=>true,'replace'=>array('from'=>$htmlFilter,'to'=>'')),
		),
		'list_url'=>'/^http:\/\/news\.wto168\.net\/zixun\/list/',
		'detail_url'=>'/^http:\/\/news\.wto168\.net\/zixun\/.*\.html/i',
		'time_limit'=>array('rule'=>'time','start'=>date('Y-m-d') ),

);

$c = new collector($config);
$url = 'http://news.wto168.net/zixun/list_56_1.html';
$res = $c->collect($url);

print_r($res);

?>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template