curl不怎么熟,百度了另外一种方法,使用Snoopy模拟登陆定时发帖实例(已测试能正常发帖),代码注释比较详细,希望有新兴趣的朋友,能加上过验证码就好了,要是那位大牛改过了还希望能发我一份代码研究,谢谢!欢迎交流 qq:1641844790
更多技术文章请移步
http://www.dahuzhi.com
header("Content-Type:text/html;charset=utf-8");
//设置浏览器关闭也运行
ignore_user_abort();
//设置超时时间
set_time_limit( 60 * 15 );
//include('Snoopy.class.php');
$snoopy = new Snoopy;
###############################################
/*模拟登陆发帖实例*****************************/
//登陆地址
$submit_url = "########";
//登录参数
$submit_vars["user_email"] = "123@123.com";
$submit_vars["password"] = "123456";
$submit_vars["issave"] = 1;
$submit_vars["redirect"] = "";
$submit_vars["login"] = "用户登录";
//用submit方法来实现登录
$snoopy->submit($submit_url, $submit_vars);
//var_dump($snoopy->results);
//要抓取的列表页
$sourceURL = "#########";
//获得网页的链接
$snoopy->fetchlinks($sourceURL);
//得到网页链接的结果
$a = $snoopy->results;
//指定获取的url正则
$p = '/mod=goods&do=display&id=/';
//收集指定采集url地址
$new = preg_grep($p,$a);
//过滤重复url
$new = array_unique($new);
$i = 1;
//循环定时发帖
foreach($new as $v)
{
//P($v);
//发帖参数
$submit_for["score"] = 4;
$submit_for["contents"] = "测试模拟发帖" . $i . '时间: ' . date('Y-n-d H:i:s', time());
$submit_for["action"] = 'ac_comm';
//用submit方法来实现发帖
$snoopy->submit($v, $submit_for);
//定时发帖
sleep(30);
$i++;
}
P('发帖完成');