Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use open ':std', ':encoding(UTF-8)';
- use HTML::Entities; # Чтобы читать русские символы в Location
- use LWP::UserAgent;
- use HTTP::Cookies;
- use HTTP::Request;
- my %result;
- my @max = (0)x4;
- my @headline = qw\ Username Clanname CC Location \;
- my $login = 'perlbot';
- my $pass = 'randompass';
- my $ua = new LWP::UserAgent;
- my $cookie_jar = new HTTP::Cookies;
- $ua->agent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36");
- $ua->show_progress('true');
- $ua->cookie_jar($cookie_jar);
- my $req = new HTTP::Request('POST', "http://forum.toribash.com/login.php?do=login");
- $req->content_type('application/x-www-form-urlencoded');
- $req->content("vb_login_username=$login&cookieuser=1&vb_login_password=$pass&do=login");
- $ua->request($req);
- sub normalize_size {
- my @argv = @_;
- my @result;
- foreach(0..3) {
- my $max = @argv[$_] > length(@argv[$_+4]) ? @argv[$_] : length(@argv[$_+4]);
- @result[$_] = $max;#max(@argv[$_], length(@argv[$_+4]));
- }
- return @result;
- }
- @max = normalize_size(@max, @headline);
- @ARGV = @ARGV ? @ARGV : <STDIN>;
- Main: foreach (@ARGV) {
- chomp($_);
- my $username = $_;
- my $code;
- my $location;
- my $clanname;
- my $index = 0;
- my @lines = split /^/, ($ua->get("http://forum.toribash.com/member.php?username=$username"))->content;
- sub parse {
- sub trim {
- my $line = @_[0];
- chomp($line);
- $line =~ s/^\s+//;
- $line =~ s/(\s+)$//;
- return $line;
- }
- my $line = $_[$_[-1]];
- while($line =~ s/<.*?>(.*?)<.*?>/$1/) { }
- return trim($line);
- }
- foreach(@lines) {
- $index++;
- if(/This user has not registered and therefore does not have a profile to view/) {
- print $username." - ".$&."\n";
- next Main;
- }
- if(/<dt class=\"shade\">Country Code<\/dt>/) {
- $code = parse(@lines, $index);
- next;
- }
- if(/<dt class=\"shade\">Location<\/dt>/) {
- $location = decode_entities(parse(@lines, $index));
- next;
- }
- if(/<dd id=\"clan\">/) {
- $clanname = parse(@lines, $index-1);
- last;
- }
- }
- my @data; $data[0] = $username; $data[1] = $clanname; $data[2] = $code; $data[3] = $location;
- @{$result{$username}} = @data;
- @max = normalize_size(@max, @data);
- }
- sub print_line {
- my @argv = @_;
- foreach(0..3) {
- my $pad = $argv[$_]+4;
- printf "%${pad}s", $argv[$_+4];
- }
- print "\n";
- }
- print_line(@max, @headline);
- foreach(keys(%result)) { print_line(@max, @{$result{$_}}); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement