溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

php如何采集中國代理服務器網(wǎng)

發(fā)布時間:2021-09-02 13:57:42 來源:億速云 閱讀:111 作者:小新 欄目:開發(fā)技術(shù)

小編給大家分享一下php如何采集中國代理服務器網(wǎng),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

具體如下:

<?php
/**
 * 采集中國代理服務器網(wǎng) 最新列表
 */
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;
  }
  /* 采集代理內(nèi)容 */
  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 '正在發(fā)送采集請求';
  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如何采集中國代理服務器網(wǎng)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

php
AI