您的位置:首页 > 移动开发 > 微信开发

抓取chinaren.com校友录留言的PHP小程序

2005-04-26 14:02 459 查看
 1  <html>
 2  <head>
 3  <metahttp-equiv="Content-Type"content="text/html; charset=gb2312">
 4  <metahttp-equiv="pragma"content="no-cache">
 5  <title>提取留言</title>
 6  <style>
 7  .head { color: red; font-weight: bold; }
 8  body { font-size: 9pt; background-color: #cccccc; }
 9  </style>
10  </head>
11  <body>
12  <?php
13  set_time_limit(600);
14
15  function getMessage($url,$history=false)
16  {
17          $match_msg  = "/<script>do.*/('[^/n]*/";
18          $match_date  = "//d{4}-/d{2}-/d{2}/040/d{2}:/d{2}:/d{2}/";
19
20          if($history==false){
21                  $match_names   = "/&cid=.{2,6}&msg=/";
22                  $replace_names = "/&cid=|&msg=/";
23          }else{
24                  $match_names   = "/class/=/"cr5/"[^/n]*/";
25                  $replace_names = "/class/=/"cr5/" target/=/"_blank/">|<//a>/";
26           }
27
28          $replace_msg   = "/<script>|<//script>|'/d*/'|doFlatTxt/('|doStr/('| [^/n]*|/'/)|/////";
29          $handle = fopen ($url, "r");
30          $contensts = "";
31          $times="";
32          $names="";
33          $messages="";
34          while ($line=fgets($handle,1024))
35          {
36                  $contents .= $line;
37          }
38          //$contents = fread ($handle, 100000);
39          //echo $contents;
40
41          fclose ($handle);
42          preg_match_all($match_date,$contents,$times);
43          preg_match_all($match_names,$contents,$names);
44          preg_match_all($match_msg,$contents,$messages);
45          for($i=0;$i<count($messages[0]);$i++)
46          {
47                  echo "<p><b>". preg_replace($replace_names,"",$names[0][$i]) ."</b>(";
48                  echo $times[0][$i]."):<br>/n";
49                  $message=preg_replace($replace_msg,"",$messages[0][$i])."/n/n";
50                  echo $message;
51          }
52  }
53
54  $begin=time();
55  echo "<p class=/"head/">最新留言:</p>/n";
56  getMessage("http://alumni.chinaren.com/class/class_index.jsp?classuuid=2815032345960598103");
57
58  echo "<p class=/"head/">更多留言:</p>/n";
59  getMessage("http://alumni.chinaren.com/class/class_leaveword.jsp?classuuid=2815032345960598103&p=1");
60  getMessage("http://alumni.chinaren.com/class/class_leaveword.jsp?classuuid=2815032345960598103&p=2");
61  getMessage("http://alumni.chinaren.com/class/class_leaveword.jsp?classuuid=2815032345960598103&p=3");
62  getMessage("http://alumni.chinaren.com/class/class_leaveword.jsp?classuuid=2815032345960598103&p=4");
63  getMessage("http://alumni.chinaren.com/class/class_leaveword.jsp?classuuid=2815032345960598103&p=5");
64  getMessage("http://alumni.chinaren.com/class/class_leaveword.jsp?classuuid=2815032345960598103&p=6");
65  getMessage("http://alumni.chinaren.com/class/class_leaveword.jsp?classuuid=2815032345960598103&p=7");
66
67  echo "<p class=/"head/">历史留言:</p>/n";
68  for($i=0;$i<100;$i++)
69  {
70   getMessage("http://alumni.chinaren.com/class/class_leaveword2.jsp?p=".$i."&classuuid=2815032345960598103&msgtype=1&type=3",true);
71  }
72
73  echo "/n<br><center><b>执行本程序用的时间是<font color=red>";
74  echo time()-$begin;
75  echo "</font>秒钟</b></center>";
76  ?>
77  </body>
78  </html>
79
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: