php curl 采集 Discuz 的代码实例
使用
php 的 curl 写的一个采集 discuz 的代码,附带模拟登陆,如果不用模拟登陆的话,直
接用
File_Get_Contents 就可以了。有需要的朋友,不妨参考下。
实现代码如下:
<?php
/**
* 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){
//<a href="viewthread.php?tid=16&extra=page%3D1">加打塔洗花腳本</a>
preg_match_all('/<a href=\"viewthread.php\?tid=(\d+)/',$code,$threads);
return $threads[1];
}
//判断该帖子是否存在