If there is a book, it is good
And when the opposite is bad
Instead of an epigraph
use WWW::Mechanize; use HTTP::Request::Common; use LWP; use LWP::UserAgent;
sudo apt-get install libwww-mechanize-perl
my $mech = WWW::Mechanize->new(); $booklog = $ARGV[0]; $bookpsw = $ARGV[1];
my $resp = $mech->get('http://www.books.ru/member/login.php'); $mech->cookie_jar->set_cookie(0, 'cookie_first_timestamp',DateTime->now->epoch, '/', 'www.books.ru'); $mech->cookie_jar->set_cookie(0, 'cookie_pages', '1', '/', 'www.books.ru'); $resp = $mech->post('http://www.books.ru/member/login.php',[ 'login' => $mail, 'password' => $password, 'go' => 'login', 'x' => rand_from_to(40, 50), 'y' => rand_from_to(1, 20), 'token' => '' ]);
$resp = $mech->get('http://www.books.ru/member/orders/'); my @order_list = mkGunz($resp->content) =~ /\<a\shref=\"http:\/\/www\.books\.ru\/order.php\?order\=(\d+)\"\>/gi; foreach my $order_id (@order_list) {...}
my $fname = ''; my $authors = ''; while (my $token = $stream->get_token) { if ($token->[0] eq 'S' && $token->[1] eq 'a') { my $href = $token->[2]{'href'}; $authors .= $stream->get_trimmed_text('/a').',' if ($href =~ /\/author\//); if ($href =~ /show\=1/) { $fname = $stream->get_trimmed_text('/a'); $fname =~ s/\(\sPDF\)//gi; } if ($href =~ /download\/\?file_type\=pdf/) { chop($authors); $fname = trim($authors.','.$fname); $fname =~ tr/\//_/; $fname .= '.pdf'; .... } }
my $gbm = $mech->clone(); $resp = $gbm->get($href); $resp = $gbm->submit_form(with_fields => {'agreed' => 'Y', 'go' => 1}); my $pdfFile = $resp->content; $pdfFile = mkGunz($resp->content) unless ($resp->content =~ /^\%PDF/); print "Saving ".$fname." as ".length($pdfFile)." bytes.\n" ; open(my $fh, ">", $fname); if (defined $fh) { binmode($fh); print $fh $pdfFile; close($fh); }
#!/usr/bin/perl use WWW::Mechanize; use HTTP::Request::Common; use LWP; use LWP::UserAgent; use URI::Escape; use HTML::TokeParser; use DateTime; use Compress::Raw::Zlib; use Encode qw(decode encode); use warnings; sub trim($); my $mech = WWW::Mechanize->new(); $booklog = $ARGV[0]; $bookpsw = $ARGV[1]; #die "Usage: books.su.pl <login> <password> \n" if (scalar @ARGV < 2); $mail = $booklog; $password = $bookpsw; $mech->agent_alias("Linux Mozilla"); #$mech->proxy('https', 'http://127.0.0.1:8888/'); #$mech->proxy('http', 'http://127.0.0.1:8888/'); my $resp = $mech->get('http://www.books.ru/member/login.php'); $mech->cookie_jar->set_cookie(0, 'cookie_first_timestamp',DateTime->now->epoch, '/', 'www.books.ru'); $mech->cookie_jar->set_cookie(0, 'cookie_pages', '1', '/', 'www.books.ru'); #print mkGunz($resp->content)."\n"; $resp = $mech->post('http://www.books.ru/member/login.php',[ 'login' => $mail, 'password' => $password, 'go' => 'login', 'x' => rand_from_to(40, 50), 'y' => rand_from_to(1, 20), 'token' => '' ]); #print mkGunz($resp->content)."\n"; $resp = $mech->get('http://www.books.ru/member/orders/'); my @order_list = mkGunz($resp->content) =~ /\<a\shref=\"http:\/\/www\.books\.ru\/order.php\?order\=(\d+)\"\>/gi; foreach my $order_id (@order_list) { $resp = $mech->get('http://www.books.ru/order.php?order='.$order_id); my $hcont = mkGunz($resp->content); my $stream = HTML::TokeParser->new(\$hcont); $stream->empty_element_tags(1); my $fname = ''; my $authors = ''; while (my $token = $stream->get_token) { if ($authors eq '' && $fname ne "" && $token->[0] eq 'S' && $token->[1] eq 'br') { $authors .= cnv($stream->get_trimmed_text('/p')).','; } if ($token->[0] eq 'S' && $token->[1] eq 'a') { my $href = $token->[2]{'href'}; if ($href =~ /show\=1/) { $fname = cnv($stream->get_trimmed_text('/a')); $fname =~ s/\(\sPDF\)//gi; } if ($href =~ /download\/\?file_type\=pdf/) { chop($authors); $fname = trim($authors.','.$fname); $fname =~ tr/\//_/; $fname .= '.pdf'; my $gbm = $mech->clone(); $resp = $gbm->get($href); $resp = $gbm->submit_form(with_fields => {'agreed' => 'Y', 'go' => 1}); my $pdfFile = $resp->content; $pdfFile = mkGunz($resp->content) unless ($resp->content =~ /^\%PDF/); print "Saving ".$fname." as ".length($pdfFile)." bytes.\n" ; open(my $fh, ">", $fname); if (defined $fh) { binmode($fh); print $fh $pdfFile; close($fh); } else { die "Unable to open:".$fname."\n"; } $authors = ''; $fname = ''; } } } } sub cnv {return shift;}#encode('cp1251', decode('UTF-8', shift));} sub rand_from_to { my($from, $to) = @_; return int(rand($to - $from)) + $from; } sub mkGunz { my ($ind) = @_; return $ind if($ind =~ /html/); my $gun = new Compress::Raw::Zlib::Inflate(WindowBits => WANT_GZIP); { my $out; my $status = $gun->inflate($ind, $out); if ($status == Z_OK || $status == Z_STREAM_END) { return $out; } else { die $status.":".$ind; } }; } sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; }
Source: https://habr.com/ru/post/236519/
All Articles