#!/usr/bin/perl use strict; use WWW::Mechanize; use LWP::ConnCache; use HTTP::Cookies; use POSIX; sub Debug($) { print join(' ', @_) . "\n" } my $dataDir = "."; # Save to the current directory. my $webUsername = 'your_web_username'; my $webPassword = 'your_web_password'; my $upsAccount = '99X99X'; # Your 6-digit UPS account number (or however many digits it is these days) # start 364 days ago. 365 breaks, so don't try it! my $start_date = strftime("%D", localtime(time() - 3600*24* 364 )); my $end_date = strftime("%D", localtime(time())); $dataDir = $ARGV[0] if (@ARGV); my $m = WWW::Mechanize->new( cookie_jar => HTTP::Cookies->new( file => $dataDir . '/cookies.txt', ignore_discard => 1, autosave => 1) ); $m->conn_cache(LWP::ConnCache->new(total_capacity => 3)); $m->agent_alias('Windows IE 6'); $m->get('https://www.ups.com/viewbill/invoices?loc=en_US&appid=BILLING'); if ($m->content =~ /type=.?password/si) { $m->get('https://www.ups.com/one-to-one/login'); Debug "logging in\n"; $m->submit_form( with_fields => { idCheckRadio => 'hasID', 'uid' => $webUsername, 'password' => $webPassword, }); $m->get('https://www.ups.com/viewbill/invoices?loc=en_US&appid=BILLING'); } else { Debug "already logged in\n"; } $start_date =~ s!/(\d\d)$!/20$1!; $end_date =~ s!/(\d\d)$!/20$1!; $m->post('https://www.ups.com/viewbill/invoices', { accountNumber => $upsAccount, start_date => $start_date, end_date => $end_date, search => 'Search', } ); my $content = $m->content; $content =~ s/\s+/ /gs; while ($content =~ m!