《PHP應(yīng)用:php采集中國(guó)代理服務(wù)器網(wǎng)的方法》要點(diǎn):
本文介紹了PHP應(yīng)用:php采集中國(guó)代理服務(wù)器網(wǎng)的方法,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
PHP應(yīng)用本文實(shí)例講述了php采集中國(guó)代理服務(wù)器網(wǎng)的方法.分享給大家供大家參考.具體如下:
PHP應(yīng)用
<?php
/**
* 采集中國(guó)代理服務(wù)器網(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');
$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 '正在發(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應(yīng)用希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助.
維易PHP培訓(xùn)學(xué)院每天發(fā)布《PHP應(yīng)用:php采集中國(guó)代理服務(wù)器網(wǎng)的方法》等實(shí)戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/10339.html