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程序设计有所帮助。

相关文章

Python基于scrapy采集数据时使用代理服务器的方法

本文实例讲述了Python基于scrapy采集数据时使用代理服务器的方法。分享给大家供大家参考。具体如下: # To authenticate the proxy, #you mu...

python实现通过代理服务器访问远程url的方法

本文实例讲述了python实现通过代理服务器访问远程url的方法。分享给大家供大家参考。具体如下: import urllib proxies = {'http' : 'http:/...

Python查看多台服务器进程的脚本分享

最近做自己开发用相关服务的一个checklist,就写了这个脚本,用来在跳板机去检查各个服务器上面的相关服务是否正常 使用expect登录每个机器(因为安全问题,不能直接使用ssh信任)...

在主机商的共享服务器上部署Django站点的方法

许多共享主机的服务提供商不允许运行你自己的服务进程,也不允许修改 httpd.conf 文件。 尽管如此,仍然有可能通过Web服务器产生的子进程来运行Django。 记录 如果你要使用服...

编写多线程Python服务器 最适合基础

编写多线程Python服务器 最适合基础

编写一个多线程的Python服务器。 多线程Python服务器使用以下主要模块来管理多个客户端连接。 1. Python的线程模块 2. SocketServer的 ThreadingM...