php采集中国代理服务器网的方法
2015-06-16 11:59
676 查看
本文实例讲述了php采集中国代理服务器网的方法。分享给大家供大家参考。具体如下:
<?php /** * 采集中国代理服务器网 最新列表 */ class proxy { /* 需采集列表 */ public $list; /* 代理列表 保存路径 */ public $save_path = 'proxy.txt'; /* 获取采集列表 */ function get_list($page) { $url = 'http://www.cnproxy.com/proxy(*).html'; // 处理列表 $this->list = preg_replace('/\(\*\)/', $page, $url); return $this->list; } /* 采集代理内容 */ function get($page) { $this->get_list($page); $file = stripslashes(file_get_contents($this->list)); $zz = '/<tr><td>([0-9\.]+)<SCRIPT type=text\/javascript>document\.write\(":"([\+a-z]+)\)<\/SCRIPT><\/td><td>[\w]+<\/td><td>[\w\,]+<\/td>/is'; preg_match_all($zz, $file, $temp); unset($temp[0]); $th = array('z', 'm', 'k', 'l', 'd', 'x', 'i', 'w', 'q', 'b'); $th2 = array(3, 4, 2, 9, 0, 5, 7, 6, 8, 1); foreach ($temp[2] as $k=>$v) { $v = preg_replace("/[\+]+/", '', $v); $s = str_replace($th, $th2, $v); $re .= $temp[1][$k] . ':' . $s . "\r\n"; } $this->save($re); return true; } /* 保存 */ function save($re) { return file_put_contents($this->save_path, $re, FILE_APPEND); } /* 读取 */ function read() { return file_get_contents($this->save_path); } } // 初始化采集类 $p = new proxy; $start = 1; $end = 10; // 控制 if($_GET['a'] == 'start') { echo '正在发送采集请求'; echo '<meta http-equiv="Refresh" content="3;URL=?p=1">'; } elseif(isset($_GET['p'])) { $i = $_GET['p']++; if($i >= $end+1) { exit('<meta http-equiv="Refresh" content="0;URL=?a=end">'); } else { echo '正在请求列表 '. $i .' > '. $end; if($p->get($i)) { echo '<meta http-equiv="Refresh" content="3;URL=?p='.$_GET['p']++.'">'; } } } elseif($_GET['a'] == 'end') { echo '采集完毕'; } else { echo '<form> <input type="hidden" name="a" value="start" /> <input type="submit" value="开始采集" /> </form>'; } ?>
希望本文所述对大家的php程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- 一个关于if else容易迷惑的问题
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- JSP/PHP基于Ajax的分页功能实现
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- PHP数据库长连接mysql_pconnect的细节
- Php Installing An Expansion
- PHP+Apache在Windows 9x下的安装和配置
- IIS 6 的 PHP 最佳配置方法
- 安装Apache和PHP的一些补充
- Linux Apache+MySQL+PHP
- 建立Apache+PHP+MySQL数据库驱动的动态网站
- dedecms采集过滤常用代码集合
- PHP 5.3.0 安装分析心得
- apache 环境下 php 的配置注意事项
- ASP.NET、ASP、PHP、JSP之间有什么区别?
- PHP VBS JS 函数 对照表
- C语言实现的统计php代码行数功能源码(支持文件夹、多目录)