discuz论坛自动回贴perl版

discuz论坛自动回贴perl版

呵呵~~
写得不好,只是来玩玩的

[Copy to clipboard] [ - ]
CODE:
#!/usr/bin/perl -w

use LWP;
use HTTP::Cookies;

print "="x70;
print "\n";
print "* 程序名:论坛自动回贴程序\n";
print "* 作 者:N3tl04d [url]http://smboy.bokee.com[/url]\n";
print "* 日 期:2007-11-23\n";
print "="x70;
print "\n";

if($#ARGV != 2){
    print "用法:$0 论坛地址 论坛已注册用户名 密码\n";
    print "如:$0 [url]http://smboy.bokee.com[/url] n3tl04d 123456\n";
    exit;
}

my $site=shift;
my $username=shift;
my $password=shift;

my @link;
my $formhash;
my @content=("我顶.灌水,哈哈","我是自动回贴的,吹吖","不错不错,好东西","哇!楼主好牛啊");#回复内容设定
my $ua=new LWP::UserAgent;
$ua->agent('Mozilla/5.0');
$ua->cookie_jar(new HTTP::Cookies);
my $test1=$ua->post( $site.'/logging.php?action=login&',
                                        [
                                        "referer"=>"index.php",
                                        "loginfield"=>"username",
                                        "username"=>$username,
                                        "password"=>$password,
                                        "questionid"=>"0",
                                        "answer"=>"",
                                        "cookietime"=>"2592000",
                                        "loginmode"=>"",
                                        "styleid"=>"",
                                        "loginsubmit"=>"提   交",
                                        ]
                                );

$url=$site.'/forumdisplay.php?fid=2';
$url2=$site.'/forumdisplay.php?fid=3';
$url3=$site.'/forumdisplay.php?fid=4';
$url4=$site.'/forumdisplay.php?fid=5';
$res = $ua->get($url);
$html=$res->content;
$res = $ua->get($url2);
$html.=$res->content;
$res = $ua->get($url3);
$html.=$res->content;
$res = $ua->get($url4);
$html.=$res->content;
print "获取版块数据 \n";

die "抓不到formhash" unless $html  =~ m{formhash=([\d\w]{8})\"?}gi;
$formhash= $1;

if ($res->is_success) {
    my @html=split(/\n/,$html);
    @link=();
    for(@html){
        if (m{<a href="viewthread\.php\?tid=(\d+)&amp;extra=page%3D1">}){
            push(@link,$1);
        }
    }

print "挑出有用的数据 $#link 个 \n";

for ($x=0;$x<=$#link;$x++){
   
    my $url=$site."/viewthread.php?tid=$link[$x]&extra=page%3D1";
    my $res = $ua->get($url);
    my $content=$res->content;
    die "没发现贴子标题:" unless $content =~ m{<title>(.+?)\s-}gi;   
    $r_num=int(rand($#content));#随机取回复内容
    my $posturl=$site."/post.php?action=reply&fid=2&tid=$link[$x]&extra=page%3D1&replysubmit=yes&";
    my $response=$ua->post( $posturl,
    [
    "formhash"=>$formhash,
    "isblog"=>"",
    "readperm"=>"0",
    "price"=>"0",
    "typeid"=>"0",
    "subject"=>'Re:回复',
    "iconid"=>"0",
    "parseurloff"=>"0",
    "smileyoff"=>"0",
    "bbcodeoff"=>"0",
    "usesig"=>"1",
    "emailnotify"=>"0",
    "message"=>$content[$r_num],
    "toxiaban"=>"",
    "wysiwyg"=>"1",
    ]
    );
    if ($response->status_line eq '302 Found' || $response->status_line eq '200 OK') {
        print "贴子\"$1\"回贴成功!\n";
    }
    print "等待35秒 \n";
    sleep 35;
}
}

不错,好像用 WWW::Mechanize模块能省很多代码