#$ua->post( $url, \%form )
#$ua->post( $url, \@form )
#$ua->post( $url, \%form, $field_name => $value, ... )
#This method will dispatch a POST request on the given $url, with %form or @form providing the key/value pairs for the fill-in form content. Additional headers and content options are the same as for the get() method.
#This method will use the POST() function from HTTP::Request::Common to build the request. See the HTTP::Request::Common manpage for a details on how to pass form content and other advanced features.
#$ua->get( $url )
#$ua->get( $url , $field_name => $value, ... )
#This method will dispatch a GET request on the given $url. Further arguments can be given to initialize the headers of the request. These are given as separate name/value pairs. The return value is a response object. See the HTTP::Response manpage for a description of the interface it provides.
#$ua->agent('Mozilla/5.0');
use HTTP::Cookies;
use LWP;
$ua = LWP::UserAgent->new;
while (1) {
# $ua->agent("$0/0.1 " . $ua->agent);
$ua->agent("Mozilla/8.0"); # pretend we are very capable browser
#获取版块数据
$url='http://www3.5hxy.com/bbs/ShowForum.asp?ForumID=1';
$url2='http://www3.5hxy.com/bbs/ShowForum.asp?ForumID=7';
$url3='http://www3.5hxy.com/bbs/ShowForum.asp?ForumID=3';
$res = $ua->get($url);
$htms=$res->content;
$res = $ua->get($url2);
$htms.=$res->content;
$res = $ua->get($url3);
$htms.=$res->content;
print "获取版块数据 \n";
#获取后挑出有用的数据
if ($res->is_success) {
@html=();
@html=split(/\n/,$htms);
@link=();
for(@html){
if (m{}){
push(@link,$1);
}
#$1 and
#}while m{};
}
}
print "挑出有用的数据 $#link 个 \n";
#历史记录
open (FILE,'D:\bin\posttools\dingtie\data\history.log');
@history=();
@history=
close FILE;
#用户记录
open(FILE,'D:\bin\posttools\dingtie\data\user.txt');
@usertxt=();
@usertxt=
close FILE;
#提交记录
open(FILE,'D:\bin\posttools\dingtie\data\posttxt.txt');
@posttxt=();
@posttxt=
close FILE;
print "用户记录 \n";
#检查帖子是否在历史,不在就回帖
$chazhao=0;#是否找到0没找到
for ($x=0;$x<=$#link;$x++){
for ($a=0;$a<=$#history;$a++){
if ($history[$a]==$link[$x]){
$a=$#history+1;
$chazhao=1;
}
}
print "帖子 $link[$x] 找到标志为 $chazhao\n";
if ($chazhao==0){ #如果历史没有就回帖
$tiezi=int(rand($#usertxt));#随即数决定发几个帖子
print "决定发 $tiezi 个帖子\n";
for ($y=0;$y<=$tiezi;$y++){
$userc=int(rand($#usertxt));#选择哪个用户
print "决定哪个用户发 $userc 个帖子\n";
$neirong=int(rand($#posttxt));#选择哪个帖子
print "决定发哪个帖子 $neirong \n";
chomp($usertxt[$userc]);
($user,$pass)=split(/,/,$usertxt[$userc]);
$ua->cookie_jar(HTTP::Cookies->new(file => "D:\\bin\\posttools\\dingtie\\data\\$user\\cookie.txt",
autosave => 1));
#以用户身份看一下帖子
$url="http://www3.5hxy.com/bbs/ShowPost.asp?ThreadID= $link[$x]";
$res = $ua->get($url);
$res->content=~m//m;
$postid=$1;
$url='http://www3.5hxy.com/bbs/AddPost.asp';
#开始发帖子
$response = $ua->post( $url,
[ThreadID => $link[$x],
PostID=> $postid,
Body => $posttxt[$neirong],
DisableYBBCode=> '1',
EditSubmit =>' 回复 '],
referer=>'http://www3.5hxy.com/bbs/', );
print "帖子回复完毕,内容 $posttxt[$neirong] \n";
sleep 5;
}
print "帖子 $link[$x] 记录历史完毕 \n";
open (FILE,'>>D:\bin\posttools\dingtie\data\history.log'); #回过帖子的记录起来
print FILE "$link[$x]\n";
close FILE;
}
$chazhao=0;
}
print "休眠600秒 \n";
sleep 600;
}
没有评论:
发表评论