首页 > 开发 > PHP > 正文

php采集中国代理服务器网的方法

2024-05-04 23:36:16
字体:大 中 小
来源:转载
供稿:网友

这篇文章主要介绍了php采集中国代理服务器网的方法,涉及php采集的相关使用技巧,需要的朋友可以参考下

本文实例讲述了php采集中国代理服务器网的方法。分享给大家供大家参考。具体如下:

 

 
  1. <?php 
  2. /** 
  3. * 采集中国代理服务器网 最新列表 
  4. */ 
  5. class proxy 
  6. { 
  7. /* 需采集列表 */ 
  8. public $list; 
  9. /* 代理列表 保存路径 */ 
  10. public $save_path = 'proxy.txt'; 
  11. /* 获取采集列表 */ 
  12. function get_list($page) 
  13. { 
  14. $url = 'http://www.cnproxy.com/proxy(*).html'; 
  15. // 处理列表 
  16. $this->list = preg_replace('//(/*/)/', $page, $url); 
  17. return $this->list; 
  18. } 
  19. /* 采集代理内容 */ 
  20. function get($page) 
  21. { 
  22. $this->get_list($page); 
  23. $file = stripslashes(file_get_contents($this->list)); 
  24. $zz = '/<tr><td>([0-9/.]+)<SCRIPT type=text//javascript>document/.write/(":"([/+a-z]+)/)<//SCRIPT><//td><td>[/w]+<//td><td>[/w/,]+<//td>/is'; 
  25. preg_match_all($zz, $file, $temp); 
  26. unset($temp[0]); 
  27. $th = array('z', 'm', 'k', 'l', 'd', 'x', 'i', 'w', 'q', 'b'); 
  28. $th2 = array(3, 4, 2, 9, 0, 5, 7, 6, 8, 1); 
  29. foreach ($temp[2] as $k=>$v) { 
  30. $v = preg_replace("/[/+]+/", '', $v); 
  31. $s = str_replace($th, $th2, $v); 
  32. $re .= $temp[1][$k] . ':' . $s . "/r/n"; 
  33. } 
  34. $this->save($re); 
  35. return true; 
  36. } 
  37. /* 保存 */ 
  38. function save($re) 
  39. { 
  40. return file_put_contents($this->save_path, $re, FILE_APPEND); 
  41. } 
  42. /* 读取 */ 
  43. function read() 
  44. { 
  45. return file_get_contents($this->save_path); 
  46. } 
  47. } 
  48. // 初始化采集类 
  49. $p = new proxy; 
  50. $start = 1; 
  51. $end = 10; 
  52. // 控制 
  53. if($_GET['a'] == 'start') { 
  54. echo '正在发送采集请求'; 
  55. echo '<meta http-equiv="Refresh" content="3;URL=?p=1">'; 
  56. } elseif(isset($_GET['p'])) { 
  57. $i = $_GET['p']++; 
  58. if($i >= $end+1) { 
  59. exit('<meta http-equiv="Refresh" content="0;URL=?a=end">'); 
  60. } else { 
  61. echo '正在请求列表 '. $i .' > '. $end; 
  62. if($p->get($i)) { 
  63. echo '<meta http-equiv="Refresh" content="3;URL=?p='.$_GET['p']++.'">'; 
  64. } 
  65. } 
  66. } elseif($_GET['a'] == 'end') { 
  67. echo '采集完毕'; 
  68. } else { 
  69. echo '<form> 
  70. <input type="hidden" name="a" value="start" /> 
  71. <input type="submit" value="开始采集" /> 
  72. </form>'; 
  73. } 
  74. ?> 

希望本文所述对大家的php程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表