Home > Backend Development > PHP Tutorial > How to collect China proxy server network in PHP, collect China_PHP tutorial

How to collect China proxy server network in PHP, collect China_PHP tutorial

WBOY
Release: 2016-07-13 09:50:32
Original
709 people have browsed it

How to collect China's proxy server network in php, collect China

This article describes the method of php to collect China's proxy server network. Share it with everyone for your reference. The details are as follows:

<&#63;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=&#63;p=1">';
} elseif(isset($_GET['p'])) {
  $i = $_GET['p']++;
  if($i >= $end+1) {
    exit('<meta http-equiv="Refresh" content="0;URL=&#63;a=end">');
  } else {
    echo '正在请求列表 '. $i .' > '. $end;
    if($p->get($i)) {
      echo '<meta http-equiv="Refresh" content="3;URL=&#63;p='.$_GET['p']++.'">';
    }
  }
} elseif($_GET['a'] == 'end') {
  echo '采集完毕';
} else {
  echo '<form>
      <input type="hidden" name="a" value="start" />
      <input type="submit" value="开始采集" />
     </form>';
}
&#63;>

Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1017887.htmlTechArticleHow to collect China's proxy server network in php, collect China. This article describes the method of php's collection of China's proxy server network. Share it with everyone for your reference. The details are as follows: php/**...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template