Home  >  Article  >  php教程  >  采集中国代理服务器网

采集中国代理服务器网

PHP中文网
PHP中文网Original
2016-05-25 17:14:541483browse

php代码

<?php
/**
 * 采集中国代理服务器网 最新列表
 */
class proxy
{
    /* 需采集列表   */
    public $list;

    /* 代理列表 保存路径 */
    public $save_path = &#39;proxy.txt&#39;;

    /* 获取采集列表 */
    function get_list($page)
    {
        $url = &#39;http://www.cnproxy.com/proxy(*).html&#39;;

        // 处理列表
        $this->list = preg_replace(&#39;/\(\*\)/&#39;, $page, $url);
        return $this->list;
    }

    /* 采集代理内容 */
    function get($page)
    {
        $this->get_list($page);
        $file = stripslashes(file_get_contents($this->list));
        $zz = &#39;/<tr><td>([0-9\.]+)<SCRIPT type=text\/javascript>document\.write\(":"([\+a-z]+)\)<\/SCRIPT><\/td><td>[\w]+<\/td><td>[\w\,]+<\/td>/is&#39;;
        preg_match_all($zz, $file, $temp);
        unset($temp[0]);
        $th = array(&#39;z&#39;, &#39;m&#39;, &#39;k&#39;, &#39;l&#39;, &#39;d&#39;, &#39;x&#39;, &#39;i&#39;, &#39;w&#39;, &#39;q&#39;, &#39;b&#39;);
        $th2 = array(3, 4, 2, 9, 0, 5, 7, 6, 8, 1);
        foreach ($temp[2] as $k=>$v) {
            $v = preg_replace("/[\+]+/", &#39;&#39;, $v);
            $s = str_replace($th, $th2, $v);
            $re .= $temp[1][$k] . &#39;:&#39; . $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[&#39;a&#39;] == &#39;start&#39;) {
    echo &#39;正在发送采集请求&#39;;
    echo &#39;<meta http-equiv="Refresh" content="3;URL=?p=1">&#39;;
} elseif(isset($_GET[&#39;p&#39;])) {
    $i = $_GET[&#39;p&#39;]++;
    if($i >= $end+1) {
        exit(&#39;<meta http-equiv="Refresh" content="0;URL=?a=end">&#39;);
    } else {
        echo &#39;正在请求列表 &#39;. $i .&#39; > &#39;. $end;
        if($p->get($i)) {
            echo &#39;<meta http-equiv="Refresh" content="3;URL=?p=&#39;.$_GET[&#39;p&#39;]++.&#39;">&#39;;
        }
    }
}  elseif($_GET[&#39;a&#39;] == &#39;end&#39;) {
    echo &#39;采集完毕&#39;;
} else {
    echo &#39;<form>
            <input type="hidden" name="a" value="start" />
            <input type="submit" value="开始采集" />
          </form>&#39;;
}
?>
Statement:
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