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


1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
4 <meta http-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/('|&nbsp[^/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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值