-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlwp.pl
35 lines (27 loc) · 877 Bytes
/
lwp.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl
use v5.10;
use HTTP::Request;
use LWP::UserAgent;
use HTTP::Cookies;
use IO::Socket::SSL;
use Mozilla::CA;
my $user = $ARGV[0];
my $pass = $ARGV[1];
my $file = "$ENV{HOME}/Dropbox/Public/instapaper.epub";
my $ua = LWP::UserAgent->new(cookie_jar =>
HTTP::Cookies->new(file => "/tmp/cookies.txt", autosave => 1));
my $req = HTTP::Request->new( POST => 'https://www.instapaper.com/user/login',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'username=' . $user . '&password=' . $pass);
# Log In
my $res = $ua->request($req);
$res->content =~ m/Logging in/g ?
say 'Logged in' : ( say 'Couldn\'t Log In' and exit 1 );
say 'Getting epub...';
my $epub = $ua->request(
HTTP::Request->new(GET => 'https://www.instapaper.com/epub')
);
open my $fh, '>', $file;
print $fh $epub->content;
# Remove cookies
unlink('/tmp/cookies.txt');