实现代码如下:
/**
* php curl采集Discuz
* www.jbxue.com
*/
set_time_limit(0);
//cookie保存目录
$cookdir = './cookie.tmp';
//模拟请求数据
Function request($url,$action,$cookdir,$referer){
$ch = curl_init();
$options = array(CURLOPT_URL => $url,
CURLOPT_HEADER => 0,
CURLOPT_NOBODY => 0,
CURLOPT_PORT => 80,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $action,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_COOKIEJAR => $cookdir,
CURLOPT_COOKIEFILE => $cookdir,
CURLOPT_REFERER => $referer
);
curl_setopt_array($ch, $options);
$code = curl_exec($ch);
curl_close($ch);
return $code;
}
//获取帖子列表
Function getList($code){
//加打塔洗花腳本
指定的主题不存在或已被删除或正在被审核,请返回。/',$code,$error);
return isset($error[0])?false:true;
[^]*/',$code,$title_tmp);
$title = $title_tmp[0];
return $title;
}
//登录论坛/
$url = 'http://www.jbxue.com/logging.php?action=login';
$action='loginfield=username&username=see7di&password=fjin999&questionid=0&cookietime=315360000&referer=http://bbs.war3.cn/&loginsubmit=提交';
request($url,$action,$cookdir,'');
unset($action,$url);
//获取帖子列表(位于第一页的帖子)
$url = 'http://www.jbxue.com/forumdisplay.php?fid=5';
$code = request($url,'',$cookdir,'');
$tList = getList($code);
//循环抓取每個帖子內的標題
foreach($tList as $list){
$url = "http://www.jbxue.com/viewthread.php?tid={$list}";
$code = request($url,'',$cookdir,'');
if(isExits($code)){
$title = getTitle($code);
echo "tid:{$list}:",strip_tags($title),"
";
}else{
echo "tid:{$list}:该帖子不存在!
";
}
}
?>