温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

php如何采集中国代理服务器网

发布时间:2021-09-02 13:57:42 来源:亿速云 阅读:109 作者:小新 栏目:开发技术

小编给大家分享一下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');
    $th3 = 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, $th3, $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如何采集中国代理服务器网”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php
AI