免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2834 | 回复: 1
打印 上一主题 下一主题

discuz论坛自动回贴perl版 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-11-24 19:14 |只看该作者 |倒序浏览
呵呵~~
写得不好,只是来玩玩的

  1. #!/usr/bin/perl -w

  2. use LWP;
  3. use HTTP::Cookies;

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

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

  16. my $site=shift;
  17. my $username=shift;
  18. my $password=shift;

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

  39. $url=$site.'/forumdisplay.php?fid=2';
  40. $url2=$site.'/forumdisplay.php?fid=3';
  41. $url3=$site.'/forumdisplay.php?fid=4';
  42. $url4=$site.'/forumdisplay.php?fid=5';
  43. $res = $ua->get($url);
  44. $html=$res->content;
  45. $res = $ua->get($url2);
  46. $html.=$res->content;
  47. $res = $ua->get($url3);
  48. $html.=$res->content;
  49. $res = $ua->get($url4);
  50. $html.=$res->content;
  51. print "获取版块数据 \n";

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

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

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

  63. for ($x=0;$x<=$#link;$x++){
  64.    
  65.     my $url=$site."/viewthread.php?tid=$link[$x]&extra=page%3D1";
  66.     my $res = $ua->get($url);
  67.     my $content=$res->content;
  68.     die "没发现贴子标题:" unless $content =~ m{<title>(.+?)\s-}gi;   
  69.     $r_num=int(rand($#content));#随机取回复内容
  70.     my $posturl=$site."/post.php?action=reply&fid=2&tid=$link[$x]&extra=page%3D1&replysubmit=yes&";
  71.     my $response=$ua->post( $posturl,
  72.     [
  73.     "formhash"=>$formhash,
  74.     "isblog"=>"",
  75.     "readperm"=>"0",
  76.     "price"=>"0",
  77.     "typeid"=>"0",
  78.     "subject"=>'Re:回复',
  79.     "iconid"=>"0",
  80.     "parseurloff"=>"0",
  81.     "smileyoff"=>"0",
  82.     "bbcodeoff"=>"0",
  83.     "usesig"=>"1",
  84.     "emailnotify"=>"0",
  85.     "message"=>$content[$r_num],
  86.     "toxiaban"=>"",
  87.     "wysiwyg"=>"1",
  88.     ]
  89.     );
  90.     if ($response->status_line eq '302 Found' || $response->status_line eq '200 OK') {
  91.         print "贴子\"$1\"回贴成功!\n";
  92.     }
  93.     print "等待35秒 \n";
  94.     sleep 35;
  95. }
  96. }
复制代码

论坛徽章:
0
2 [报告]
发表于 2007-11-25 12:38 |只看该作者
不错,好像用 WWW::Mechanize模块能省很多代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP