|
|
Question : perl script upgrade
|
|
The script I have is working fine but needs an addition. It currently goes through all the urls in urls.txt and takes a random line from data.txt and submits the form. I need it to still randomly choose a line from data.txt, but then not use that line again.
Thanks
use WWW::Mechanize;
$|++;
## setup variables my $URLFILE = 'craigseroticservicesurls.txt'; my $DATAFILE = 'datageneral.txt';
my $mech = WWW::Mechanize->new();
## read in data my @datalines = slurp_file($DATAFILE); my @urls = slurp_file($URLFILE);
## loop over urls foreach my $url(@urls) { my $res = $mech->get($url);
my %data = get_data($datalines[rand(@datalines)]); $mech->set_fields(%data); $mech->submit(); $mech->submit(); # need to confirm the previous post print "Posting to $url was" . ($mech->success()?'':' *NOT*') . " successful$/"; } ## gets post data for form sub get_data { my ($line) = @_; my ($subject,$body, $email, $chkbox) = split /\|/, $line; my %data = ( ### hidden fields in the form postingSubject => $subject, # your subject postingDescription => $body, # your body postingReplyEmail => $email, # your email address privacy => $chkbox, # your 'checkbox' (one of P, C, A) ); return %data; }
### slurps lines from file sub slurp_file { my $file = shift; open F, $file or die "Error opening $file: $!"; my @lines = map { chomp; $_ } ; close F; return @lines; }
|
Answer : perl script upgrade
|
|
Ah, didn't see the loop there. Do you want which links have been chosen to persist between runnings of the script? If not, this will suffice:
## loop over urls foreach my $url(@urls) { my $res = $mech->get($url);
my $rn = rand(@datalines); # <-- added my %data = get_data($datalines[$rn]); # <-- changed splice(@datalines,$rn,1); # <-- added
$mech->set_fields(%data); $mech->submit(); $mech->submit(); # need to confirm the previous post print "Posting to $url was" . ($mech->success()?'':' *NOT*') . " successful$/"; }
|
|
|
|
|