PHP开发者常用的简易Web采集器V2版有哪些特点?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1209个文字,预计阅读时间需要5分钟。
“一款面向程序员的简单网页采集工具;支持无需登录及权限认证即可访问页面资源的采集功能,包括文章、下载资源等;项目地址http://github.com/itziy/gather;目前暂时‘‘
;一个针对程序员编写的简单的网页采集工具;目前只支持不需要进行登录及权限认证即可访问的页面资源的采集功能,包括文章、下载资源等
;项目地址github.com/itziy/gather
;目前暂时不支持IP代理功能,有需要的朋友可以自己进行扩展
;目前暂时不支持只提供临时下载地址的资源的采集,即没有做本地化的处理功能
;
;功能描述
;1.支持多次跳转的资源下载功能
;2.支持采集内容的字符替换功能
;3.支持断点继续采集功能,根据设置PAGE_START参数
;
;作者:Rain
;联系QQ:563268276
;网址:www.94cto.com/www.itziy.com/www.verypan.com
;时间:2015-04-23
;版本:V2
;版权:可以进行任意修改,再发布及自己学习使用,不可用于非法用途,否则后果自负
;
;使用方式
#默认的配置文件名称是当前执行目录下的conf.ini
#phpgather.phpconf.ini
;温馨提示:默认情况下,我们认定Linux系统默认命令行编码为utf-8,window系统命令行的编码为GBK编码
1.[文件] gather.php~15KB 下载(50)
<?php /** ; 一个针对程序员编写的简单的网页采集工具 ; 目前只支持不需要进行登录及权限认证即可访问的页面资源的采集功能,包括文章、下载资源等 ; 目前暂时不支持IP代理功能,有需要的朋友可以自己进行扩展 ; 目前暂时不支持只提供临时下载地址的资源的采集,即没有做本地化的处理功能 ; ; 功能描述 ; 1.支持多次跳转的资源下载功能 ; 2.支持采集内容的字符替换功能 ; 3.支持断点继续采集功能,根据设置PAGE_START参数 ; ; 作者:Rain ; 联系QQ:563268276 ; 网址:www.94cto.com / www.itziy.com / www.verypan.com ; 时间:2015-04-23 ; 版本:V2 ; 版权:可以进行任意修改,再发布及自己学习使用,不可用于非法用途,否则后果自负 ; ; 使用方式 # 默认的配置文件名称是当前执行目录下的conf.ini # php gather.php conf.ini ; 温馨提示:默认情况下,我们认定Linux系统默认命令行编码为utf-8,window系统命令行的编码为GBK编码 */ $conf_file = dirname(__FILE__).'/conf.ini'; if (isset($argv[1]) && ($argv[1] == 'h' || $argv[1] == 'help' || $argv[1] == '-h' || $argv[1] == '--help')) die('usage: php gather.php conf.ini'); if (isset($argv[1])) $conf_file = $argv[1]; if (!file_exists($conf_file)) die('configuration file: '.$conf_file.' not find'); $confArr = parse_ini_file($conf_file, true); if (!is_array($confArr) || empty($confArr)) die('configuration file: '.$conf_file.' invalid'); if (!isset($confArr['CONST']) || !isset($confArr['VARIABLE'])) die('configuration file: '.$conf_file.' invalid'); //init const variable foreach ($confArr['CONST'] as $ck => $cv) { if (!defined($ck)) define($ck, $cv); } //init global variable foreach ($confArr['VARIABLE'] as $vk => $vv) { $$vk = $vv; } $ga = new Gather(); $ga->run(); class Gather { public function __construct() { $this->init_check(); } public function run() { global $table_mapping, $text_filter, $preDownArr, $downArr, $need_host_check_field_name; for ($page = PAGE_START; $page <= PAGE_COUNT; $page++) { $this->write('开始采集列表第'.$page.'页的内容...'); $list_content = $this->get(sprintf(WEB_LIST_URL, $page)); if (empty($list_content)) { $this->write('抓取的列表页的内容为空,所以过滤掉'); continue; } $list_content = str_replace("\r", '', $list_content); $list_content = str_replace("\n", '', $list_content); //精准定位要抓取的模块内容 if (!preg_match(WEB_LIST_POSTION, $list_content, $list_search)) { $this->write('精准匹配列表页的内容失败,所以过滤掉'); continue; } if (isset($list_search[1])) $list_content = $list_search[1]; else $list_content = $list_search[0]; //end preg_match_all(WEB_CONTENT_URL_REG, $list_content, $match); $this->write('实际抓取的内容记录条数'.count($match[0])); if (isset($match[1]) && is_array($match[1]) && !empty($match[1])) $match[0] = $match[1]; if (is_array($match[0]) && !empty($match[0])) { $this->write('当前的列表页面,总共匹配到:'.count($match[0]).'个内容页'); foreach ($match[0] as $kval => $val) { if (strpos($val, 'www.baidu.com/search/spider.htm)"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_HEADER, $showhead); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $data); $ret = curl_exec($ch); $error = curl_error($ch); curl_close($ch); unset($ch); if (!empty($error)) { $this->write('程序抓取URL: '.$url.'发生错误,错误信息: '.$error); return false; } if (WEB_CHARSET != 'utf-8') $ret = iconv(WEB_CHARSET, 'utf-8', $ret); return $ret; } //when check finish,mysql connect will auto close private function check_mysql_connect() { $con = mysql_connect(DB_HOST, DB_USER, DB_PWD); if (!is_resource($con)) $this->write('程序无法成功链接到数据库,具体的错误信息:'.mysql_error(), true); if (!mysql_select_db(DB_NAME, $con)) $this->write('程序无法链接到数据库: '.DB_NAME.',具体的错误信息: '.mysql_error(), true); mysql_close($con); } private function check_curl_support() { if (!extension_loaded('curl') || !function_exists('curl_init')) return false; return true; } private function write($str, $end = false) { if (PATH_SEPARATOR == ':') echo $str,PHP_EOL,PHP_EOL; else echo iconv('UTF-8', 'GBK', $str),PHP_EOL,PHP_EOL; if ($end) die("program exit"); sleep(OUTPUT_SPEED); } }
2.[文件] conf.ini~7KB 下载(69)
本文共计1209个文字,预计阅读时间需要5分钟。
“一款面向程序员的简单网页采集工具;支持无需登录及权限认证即可访问页面资源的采集功能,包括文章、下载资源等;项目地址http://github.com/itziy/gather;目前暂时‘‘
;一个针对程序员编写的简单的网页采集工具;目前只支持不需要进行登录及权限认证即可访问的页面资源的采集功能,包括文章、下载资源等
;项目地址github.com/itziy/gather
;目前暂时不支持IP代理功能,有需要的朋友可以自己进行扩展
;目前暂时不支持只提供临时下载地址的资源的采集,即没有做本地化的处理功能
;
;功能描述
;1.支持多次跳转的资源下载功能
;2.支持采集内容的字符替换功能
;3.支持断点继续采集功能,根据设置PAGE_START参数
;
;作者:Rain
;联系QQ:563268276
;网址:www.94cto.com/www.itziy.com/www.verypan.com
;时间:2015-04-23
;版本:V2
;版权:可以进行任意修改,再发布及自己学习使用,不可用于非法用途,否则后果自负
;
;使用方式
#默认的配置文件名称是当前执行目录下的conf.ini
#phpgather.phpconf.ini
;温馨提示:默认情况下,我们认定Linux系统默认命令行编码为utf-8,window系统命令行的编码为GBK编码
1.[文件] gather.php~15KB 下载(50)
<?php /** ; 一个针对程序员编写的简单的网页采集工具 ; 目前只支持不需要进行登录及权限认证即可访问的页面资源的采集功能,包括文章、下载资源等 ; 目前暂时不支持IP代理功能,有需要的朋友可以自己进行扩展 ; 目前暂时不支持只提供临时下载地址的资源的采集,即没有做本地化的处理功能 ; ; 功能描述 ; 1.支持多次跳转的资源下载功能 ; 2.支持采集内容的字符替换功能 ; 3.支持断点继续采集功能,根据设置PAGE_START参数 ; ; 作者:Rain ; 联系QQ:563268276 ; 网址:www.94cto.com / www.itziy.com / www.verypan.com ; 时间:2015-04-23 ; 版本:V2 ; 版权:可以进行任意修改,再发布及自己学习使用,不可用于非法用途,否则后果自负 ; ; 使用方式 # 默认的配置文件名称是当前执行目录下的conf.ini # php gather.php conf.ini ; 温馨提示:默认情况下,我们认定Linux系统默认命令行编码为utf-8,window系统命令行的编码为GBK编码 */ $conf_file = dirname(__FILE__).'/conf.ini'; if (isset($argv[1]) && ($argv[1] == 'h' || $argv[1] == 'help' || $argv[1] == '-h' || $argv[1] == '--help')) die('usage: php gather.php conf.ini'); if (isset($argv[1])) $conf_file = $argv[1]; if (!file_exists($conf_file)) die('configuration file: '.$conf_file.' not find'); $confArr = parse_ini_file($conf_file, true); if (!is_array($confArr) || empty($confArr)) die('configuration file: '.$conf_file.' invalid'); if (!isset($confArr['CONST']) || !isset($confArr['VARIABLE'])) die('configuration file: '.$conf_file.' invalid'); //init const variable foreach ($confArr['CONST'] as $ck => $cv) { if (!defined($ck)) define($ck, $cv); } //init global variable foreach ($confArr['VARIABLE'] as $vk => $vv) { $$vk = $vv; } $ga = new Gather(); $ga->run(); class Gather { public function __construct() { $this->init_check(); } public function run() { global $table_mapping, $text_filter, $preDownArr, $downArr, $need_host_check_field_name; for ($page = PAGE_START; $page <= PAGE_COUNT; $page++) { $this->write('开始采集列表第'.$page.'页的内容...'); $list_content = $this->get(sprintf(WEB_LIST_URL, $page)); if (empty($list_content)) { $this->write('抓取的列表页的内容为空,所以过滤掉'); continue; } $list_content = str_replace("\r", '', $list_content); $list_content = str_replace("\n", '', $list_content); //精准定位要抓取的模块内容 if (!preg_match(WEB_LIST_POSTION, $list_content, $list_search)) { $this->write('精准匹配列表页的内容失败,所以过滤掉'); continue; } if (isset($list_search[1])) $list_content = $list_search[1]; else $list_content = $list_search[0]; //end preg_match_all(WEB_CONTENT_URL_REG, $list_content, $match); $this->write('实际抓取的内容记录条数'.count($match[0])); if (isset($match[1]) && is_array($match[1]) && !empty($match[1])) $match[0] = $match[1]; if (is_array($match[0]) && !empty($match[0])) { $this->write('当前的列表页面,总共匹配到:'.count($match[0]).'个内容页'); foreach ($match[0] as $kval => $val) { if (strpos($val, 'www.baidu.com/search/spider.htm)"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_HEADER, $showhead); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $data); $ret = curl_exec($ch); $error = curl_error($ch); curl_close($ch); unset($ch); if (!empty($error)) { $this->write('程序抓取URL: '.$url.'发生错误,错误信息: '.$error); return false; } if (WEB_CHARSET != 'utf-8') $ret = iconv(WEB_CHARSET, 'utf-8', $ret); return $ret; } //when check finish,mysql connect will auto close private function check_mysql_connect() { $con = mysql_connect(DB_HOST, DB_USER, DB_PWD); if (!is_resource($con)) $this->write('程序无法成功链接到数据库,具体的错误信息:'.mysql_error(), true); if (!mysql_select_db(DB_NAME, $con)) $this->write('程序无法链接到数据库: '.DB_NAME.',具体的错误信息: '.mysql_error(), true); mysql_close($con); } private function check_curl_support() { if (!extension_loaded('curl') || !function_exists('curl_init')) return false; return true; } private function write($str, $end = false) { if (PATH_SEPARATOR == ':') echo $str,PHP_EOL,PHP_EOL; else echo iconv('UTF-8', 'GBK', $str),PHP_EOL,PHP_EOL; if ($end) die("program exit"); sleep(OUTPUT_SPEED); } }

