+ -
当前位置:首页 → 问答吧 → discuzX2.5的自动发贴 刚用php curl写的

discuzX2.5的自动发贴 刚用php curl写的

时间:2013-04-16

来源:互联网

<?php
/* 
*  
* 作者:大水车
* 类用途: 实现discuz2.5登陆发帖 
*/
class  discuz_post{
        var $login_url;
        var $post_login_array=array(    );
        var $post_url;
        var $cookie_file;
        public function get_formhash($login_url){
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $login_url);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $contents = curl_exec($ch);//print_r($contents);die;
                curl_close($ch);
                //正常发布的版本用如下方法可以获得登陆部分的formhash
                preg_match('/<input type="hidden" name="formhash" value="(.*)" \/>/isU', $contents, $matches);
                //echo "<pre>";
                //print_r($matches);die;
                if(!empty($matches)) {
                        $formhash = $matches[1];
                } else {
                //      die('Not found the forumhash.');
                }
                return $formhash;
        }
        
        public function getcookie($login_url,$post){
                $cookie_file = tempnam('./temp','cookie');
                //print_r($cookie_file);die;
                $ch = curl_init($login_url);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
                curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
                curl_exec($ch);
                curl_close($ch);
                $this->cookie_file=$cookie_file;
                return $cookie_file;
                
        }
        
        public function use_cookie($send_url){
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $send_url);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
                $contents = curl_exec($ch);
                curl_close($ch);
                //获得发帖页面的fromhash
                preg_match_all('/<input type="hidden" name="formhash" id="formhash" value="(.*)" \/>/isU',$contents,$matches);
                if(!empty($matches)){
                        $formhash = $matches[1][0];
                }else {
                        $formhash='';//没有
                }
                return $formhash;
                
        }
        
        public function post_newthread($send_url,$thread_data){
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $send_url);
                curl_setopt($ch, CURLOPT_REFERER, $send_url);//伪装REFERER
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $thread_data);
                $contents = curl_exec($ch);
                curl_close($ch);
                return 1;
                
        }

}

//下面是代码例子*******************************************************************************
$rc= new discuz_post();
//登陆的地址
$login_url='http://bbs.phpchina.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes';

$theformhash= $rc->get_formhash($login_url);
//登陆部分需要发送的数据,这里处理没有验证码的
$login_array=array(
                                        'username'=>'用户名',
                                        'password'=>'密码',
                                        'referer'=>'http://bbs.phpchina.com/',
                                        'questionid'=>0,
                                        'answer'=>'',
                                        'seccodeverify'=>'',
                                        'formhash'=>$theformhash,//这个貌似没有也可以发帖滴
                   );
//获得cookie文件
$the_cookie_file= $rc->getcookie($login_url,$login_array);
$send_url ='http://bbs.phpchina.com/forum.php?mod=post&action=newthread&fid=2&infloat=yes';
$thesendformhash= $rc->use_cookie($send_url);//利用cookie文件的
$post_array=array(
             'subject' => "发帖,发帖测试",//标题
                         'message' =>" 内容噢噢噢噢噢噢噢噢",//要超过10个字,奶奶的
                         'topicsubmit' => "yes",
                         'extra' => '',
                         'tags' => 'Curl',//帖子标签
                         'formhash'=>$thesendformhash,                        
                        );
$rc->post_newthread($send_url,$post_array);//发了一贴
echo "<pre>";
print_r($rc);
echo $theformhash;
echo $the_cookie_file;
echo $thesendformhash;
unlink($rc->cookie_file);//删除cookie文件,也可以不删除
echo "ok!";





作者: 大水车   发布时间: 2013-04-16

<?php
/*
*  
* 作者:大水车
* 类用途: 实现discuz2.5登陆发帖
*/
class  discuz_post{
        var $login_url;
        var $post_login_array=array(        );
        var $post_url;
        var $cookie_file;
        public function get_formhash($login_url){
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $login_url);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $contents = curl_exec($ch);//print_r($contents);die;
                curl_close($ch);
                //正常发布的版本用如下方法可以获得登陆部分的formhash
                preg_match('/<input type="hidden" name="formhash" value="(.*)" \/>/isU', $contents, $matches);
                //echo "<pre>";
                //print_r($matches);die;
                if(!empty($matches)) {
                        $formhash = $matches[1];
                } else {
                //        die('Not found the forumhash.');
                }
                return $formhash;
        }
       
        public function getcookie($login_url,$post){
                $cookie_file = tempnam('./temp','cookie');
                //print_r($cookie_file);die;
                $ch = curl_init($login_url);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
                curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
                curl_exec($ch);
                curl_close($ch);
                $this->cookie_file=$cookie_file;
                return $cookie_file;
               
        }
       
        public function use_cookie($send_url){
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $send_url);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
                $contents = curl_exec($ch);
                curl_close($ch);
                //获得发帖页面的fromhash
                preg_match_all('/<input type="hidden" name="formhash" id="formhash" value="(.*)" \/>/isU',$contents,$matches);
                if(!empty($matches)){
                        $formhash = $matches[1][0];
                }else {
                        $formhash='';//没有
                }
                return $formhash;
               
        }
       
        public function post_newthread($send_url,$thread_data){
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $send_url);
                curl_setopt($ch, CURLOPT_REFERER, $send_url);//伪装REFERER
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $thread_data);
                $contents = curl_exec($ch);
                curl_close($ch);
                return 1;
               
        }

}

//下面是代码例子*******************************************************************************
$rc= new discuz_post();
//登陆的地址
$login_url='http://bbs.phpchina.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes';

$theformhash= $rc->get_formhash($login_url);
//登陆部分需要发送的数据,这里处理没有验证码的
$login_array=array(
                                        'username'=>'用户名',
                                        'password'=>'密码',
                                        'referer'=>'http://bbs.phpchina.com/',
                                        'questionid'=>0,
                                        'answer'=>'',
                                        'seccodeverify'=>'',
                                        'formhash'=>$theformhash,//这个貌似没有也可以发帖滴
                   );
//获得cookie文件
$the_cookie_file= $rc->getcookie($login_url,$login_array);
$send_url ='http://bbs.phpchina.com/forum.php?mod=post&action=newthread&fid=2&infloat=yes';
$thesendformhash= $rc->use_cookie($send_url);//利用cookie文件的
$post_array=array(
             'subject' => "发帖,发帖测试",//标题
                         'message' =>" 内容噢噢噢噢噢噢噢噢",//要超过10个字,奶奶的
                         'topicsubmit' => "yes",
                         'extra' => '',
                         'tags' => 'Curl',//帖子标签
                         'formhash'=>$thesendformhash,                         
                        );
$rc->post_newthread($send_url,$post_array);//发了一贴
echo "<pre>";
print_r($rc);
echo $theformhash;
echo $the_cookie_file;
echo $thesendformhash;
unlink($rc->cookie_file);//删除cookie文件,也可以不删除
echo "ok!";
?>

作者: 大水车   发布时间: 2013-04-16

图片上传呢?我写的采集发贴貌似被我整理硬盘的时候删了。。。。都是日本电影惹的祸

作者: shenshike   发布时间: 2013-04-16

{:soso_e161:}

作者: webdna   发布时间: 2013-04-17

shenshike 发表于 2013-4-16 23:47
图片上传呢?我写的采集发贴貌似被我整理硬盘的时候删了。。。。都是日本电影惹的祸 ...

你写过图片上传?

作者: 大水车   发布时间: 2013-04-17

shenshike 发表于 2013-4-16 23:47
图片上传呢?我写的采集发贴貌似被我整理硬盘的时候删了。。。。都是日本电影惹的祸 ...

你写过图片上传?

作者: 大水车   发布时间: 2013-04-17

赞一个,

作者: qai41   发布时间: 2013-04-17

大水车 发表于 2013-4-17 09:47
你写过图片上传?

写过呀,discuz和phpwind都写过。。。
当年买了一个采集软件居然tmd是没有图片上传的,一怒之下自己就写了。

作者: shenshike   发布时间: 2013-04-17

采集还是上传

上传是本地的,还是通过flash的上传?

作者: 大水车   发布时间: 2013-04-17

验证码的呢

作者: fansuser   发布时间: 2013-04-17

干,这个东西写起来就没完没了了

能模拟发帖就行了,

作者: 大水车   发布时间: 2013-04-17

加了一个多线程处理的

把人家论坛搞挂了,我艹!!!!!!!!!!

作者: 大水车   发布时间: 2013-04-19

我写过个爬虫,把个老外的网站干挂了,大半夜的运维也没管,一直挂了一晚上

作者: qxhy123   发布时间: 2013-04-19

上面的 post还要 修改一点点
里面的post数据超过 1024的时候要设置
有两种方法 ,curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));  
另外一个是 把http协议 CURLOPT_HTTP_VERSION CURL_HTTP_VERSION_1_0

作者: 大水车   发布时间: 2013-04-21

无论如何都得支持一下!

作者: ylyy   发布时间: 2013-04-21

用JS来做这些事情是最简单的,昨晚花了几分钟给妹子写了个美丽说吸粉的代码。
主要代码如下
var myids=new Array();
for(var i in Meilishuo.config.p4p.tInfo){
myids[i]=Meilishuo.config.p4p.tInfo[i].twitter_id;
}
function curl(){
var tid=myids.shift();
$.post("http://www.meilishuo.com/twitter/ajax_voteTwitter",{"fws":"%5B%E5%B0%8F%E7%BA%A2%E5%BF%83%5D","stid":tid,"tvd":tid});
}
var mary=setInterval("curl()", 2000);
//window.clearInterval(mary);

作者: iminto   发布时间: 2013-04-21

开始学起。

作者: ipsnowj   发布时间: 2013-04-26

你好,能帮忙发个贴么?有偿求助,我们是搞Discuz插件的
http://task.zhubajie.com/2698323/###

作者: jiahuafu   发布时间: 2013-05-02