Copy codeThe Code is as follows:
<? Php
// Wu yanjun
// 2009-06-27
// Collection program php
Set_time_limit (0 );
// Cookie storage directory
$ Cookie_jar = '/tmp/cookie. tmp ';
/* Function compute ------------------------------------------------------------------------------------------------------------*/
// Simulate request data
Function request ($ url, $ postfields, $ cookie_jar, $ referer ){
$ Ch = curl_init ();
$ Options = array (CURLOPT_URL => $ url,
CURLOPT_HEADER => 0,
CURLOPT_NOBODY => 0,
CURLOPT_PORT => 80,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $ postfields,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_COOKIEJAR => $ cookie_jar,
CURLOPT_COOKIEFILE => $ cookie_jar,
CURLOPT_REFERER => $ referer
);
Curl_setopt_array ($ ch, $ options );
$ Code = curl_exec ($ ch );
Curl_close ($ ch );
Return $ code;
}
// Obtain the post list
Function getThreadsList ($ code ){
Preg_match_all ('/<! -- [. | \ R | \ n] *? <A href = \ "viewthread. php \? Tid = (\ d +)/', $ code, $ threads );
Return $ threads [1];
}
// Determine whether the post exists
Function isExits ($ code ){
Preg_match ('/<p> the specified topic does not exist, has been deleted, or is being reviewed. Please return. <\/P>/', $ code, $ error );
Return isset ($ error [0])? False: true;
}
// Obtain the post title
Function getTitle ($ code ){
Preg_match ('/$ Title = $ title_tmp [0];
Return $ title;
}
// Obtain the post Author:
Function getAuthor ($ code ){
Preg_match ('/<a href = \ "space. php \? Uid = \ d + \ "target = \" _ blank \ "id = \" userinfo \ d + \ "onmouseover = \" showMenu \ (this \. id \) \ ">. +/', $ code, $ author_tmp );
$ Author = strip_tags ($ author_tmp [0]);
Return $ author;
}
// Obtain the content posted by the poster
Function getContents ($ code ){
Preg_match ('/<div id = \ "postmessage _ \ d + \" class = \ "t_msgfont \"> (. | \ r | \ n )*? <\/Div>/', $ code, $ contents_tmp );
$ Contents = preg_replace ('/images \ //', 'HTTP: // bbs.war3.cn/images/',#contents_tmp%0]);
Return $ contents;
}
// Print the post title
Function printTitle ($ title ){
Echo "<strong> }
// Output post author
Function printAuthor ($ author ){
Echo "<strong> }
// Print the post content
Function printContents ($ contents ){
Echo "<strong> }
// Error
Function printError (){
Echo "<I> This post does not exist! </I> ";
}
/* Function list end functions ---------------------------------------------------------------------------------------------------*/
/* Log on to the Forum begin */
$ Url = 'HTTP: // bbs.war3.cn/logging.php? Action = login ';
$ Postfields = 'loginfield = username & username = 1nject10n & password = xxxxxx & questionid = 0 & cookietime = 315360000 & referer = http://bbs.war3.cn/&loginsubmit ';
Request ($ url, $ postfields, $ cookie_jar ,'');
Unset ($ postfields, $ url );
/* Log on to the Forum end */
/* Obtain the post list (the post on the first page) begin */
$ Url = 'HTTP: // bbs.war3.cn/forumdisplay.php? Fid = 57 ';
$ Code = request ($ url, '', $ cookie_jar ,'');
$ ThreadsList = getThreadsList ($ code );
/* Get the post list end */
// Post sequence
$ Rows = 0;
/* Capture the source code of all posts cyclically */
Foreach ($ threadsList as $ list ){
$ Url = "http://bbs.war3.cn/viewthread.php? Tid = $ list ";
If (isExits ($ code )){
$ Code = request ($ url, '', $ cookie_jar ,'');
$ Color = $ rows % 2 = 0? '# 00ccff':' # FFFF33 ';
Echo "<div style = 'background-color: $ color'> ";
Echo "$ Author = getAuthor ($ code );
PrintAuthor ($ author );
$ Title = getTitle ($ code );
PrintTitle ($ title );
$ Contents = getContents ($ code );
PrintContents ($ contents );
Echo "</div> ";
$ Rows ++;
}
Else
PrintError ();
Echo "Success <br/> ";
}
/* Capture the source code end */
?>