#!/usr/bin/perl -w # get_earnings_report.pl # # Logs into Amazon, downloads earning report, # and writes an HTML version for your site. # Usage: perl get_earnings_report.pl use strict; use URI::Escape; use HTTP::Cookies; use LWP::UserAgent; use Net::SSLeay; # Set your Associates account info. my $email = 'emailaddr@yahoo.com'; my $pass = 'mypasswordhere'; my $aftag = 'amazonid'; # Create a user agent object # and fake the agent string. my $ua = LWP::UserAgent->new; $ua->agent("(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)"); $ua->cookie_jar({}); # in-memory cookie jar. # Request earning reports, logging in as one pass. my $rpturl = "https://associates.amazon.com/gp/associates/". "network/reports/main.html"; my $rptreq = HTTP::Request->new(POST => $rpturl); my $rptdata = "report-type=shipments-by-item". # get individual items "&date-selection=qtd". # all earnings this quarter "&login_id=".uri_escape($email). # our email address. "&login_password=".uri_escape($pass). # and password. "&submit.download=Download my report". # get downloadble. "&enable-login-post=true"; # log in and post at once. $rptreq->content_type('application/x-www-form-urlencoded'); $rptreq->content($rptdata); my $report = $ua->request($rptreq); print $report->content; # Set the report to array. my @lines = split(/\n/, $report->content); # Get the time period. my @fromdate = split(/\t/, $lines[1]); my @todate = split(/\t/, $lines[2]); my $from = $fromdate[1]; my $to = $todate[1]; # Print header... print "
"; print "