php采集中国代理服务器网的方法

yipeiwu_com6年前服务器

本文实例讲述了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程序设计有所帮助。

相关文章

Tornado Web服务器多进程启动的2个方法

一、Tornado简介 Tornado 是 FriendFeed 的 Web 服务器及其常用工具的开源版本。Tornado 和现在的主流 Web 服务器框架(包括大多数 Python 的...

基于win2003虚拟机中apache服务器的访问

基于win2003虚拟机中apache服务器的访问

虽然在win2003配置PHP有点非主流,但你还是要会怎么弄。你也可以将本文的虚拟机看成是服务器,宿主机看成是客户端。 不像Linux系统,由于win2003有IIS的存在,占有了固有的...

python服务器与android客户端socket通信实例

本文实例讲述了python服务器与android客户端socket通信的方法。分享给大家供大家参考。具体实现方法如下: 首先,服务器端使用python完成,下面为python代码: 复制...

Python实现简单的代理服务器

本文实例讲述了Python实现简单的代理服务器。分享给大家供大家参考。具体如下: 具备简单的管理功能,运行后 telnet localhost 9000 端口可以进行管理主要功能就是做包...

开启CURL扩展,让服务器支持PHP curl函数(远程采集)

curl()、file_get_contents()、snoopy.class.php这三个远程页面抓取或采集中用到的工具,默迹还是侵向于用snoopy.class.php,因为他效率比...