Copy the code The code is as follows:
// Wu Yanjun
// 2009-06-27
// Collection program php
set_time_limit(0);
//Cookie saving directory
$ cookie_jar = '/tmp/cookie.tmp';
/*function---------------------------------- -------------------------------------------------- -----------------------*/
//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,
C URLOPT_POSTFIELDS = > $postfields,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_COOKIEJAR => $cookie_jar,
CURLOPT_COOKIEFILE => gt; $referer
);
curl_setopt_array($ch , $options);
$code = curl_exec($ch);
curl_close($ch);
return $code;
}
//Get the post list
function getThreadsList($code){
preg_match_all('/ < !--[.|r|n]*? $author = strip_tags ($author_tmp[0]);
return $author;
}
//Get the content published by the poster
function getContents($code){
preg_match('/
$contents = preg_replace('/images//','http://bbs.war3.cn/images /',$contents_tmp[0]);
return $contents;
}
//Print post title
function printTitle($title){
echo " Post title:
",strip_tags($title),"
";
}
//Output the post author
function printAuthor($author){
echo " Post author: ",strip_tags($author),"
";
}
//Print post content
function printContents($contents){
echo " Content published by the author:
",$contents,"
";
}
//Error
function printError(){
echo " This post does not exist! ";
}
/*Function listend-------------- -------------------------------------------------- ----------------------------------*/
/*Log in to the forum begin*/
$url = ' http://bbs.war3.cn/logging.php?action=login';
$postfields='loginfield=username&username=1nject10n& password=xxxxxx&questi referer=http://bbs.war3.cn/&loginsubmit=submit';
request($url,$postfields,$cookie_jar,'');
unset($postfields,$url);
/*Log in to the forum end*/
/*Get the post list (posts 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;
/*Loop to grab all post source codes begin*/
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 "
echo " th",($rows+1),"Post :
";
$author = getAuthor($code);
printAuthor($author);
$title = getTitle($code);
printTitle($title);
$ contents = getContents($code);
printContents($contents);
echo "
$rows++;
}
else
printError();
echo "--------- -------------------------------------------------- -------------------------------
";
}
/*Catch Get the source code end*/
?>
The above introduces the hp forum php forum collection program to simulate login and capture the page implementation code, including the hp forum content. I hope it will be helpful to friends who are interested in PHP tutorials.