use WWW::Mechanize;
use Data::Dumper;
$login_email = "#########################";
$login_pwd = '######';
my $mech = WWW::Mechanize->new();
$create_obj = $mech->success();
$mech->agent_alias( 'Windows Mozilla' );
$create_alias = $mech->success();
$mech->get('https://zipcodedownload.com/login');
$first_get = $mech->success();
$mech->submit_form(
with_fields => {
Email => $login_email,
Password => $login_pwd
},
button => ""
);
### Up to here login looks good
$submit = $mech->success();
@inputs= $mech->find_all_inputs();
$inputs = scalar(@inputs);
print "num inpits is $inputs\n";
$found_page = $mech->content;
$found_page =~ /PopDownLoadProducts\('([^']+)'/;
print "Poppy is $1\n";
$download_page = "https://zipcodedownload.com/customer/GetDownLoadProductFormat?id=$1";
$mech->get("$download_page");
$second_get = $mech->success();
print "Got product is $second_get\n";
$download_page = $mech->content;
@download_pages = split /\\r\\n/, $download_page;
## I successfully find the download box
print "Num elements is " . scalar(@download_pages) . "\n";
foreach $page (@download_pages) {
$page =~ /\\u0027(.+)\\u0027\)\\"\\u003eComma/;
$foundit="";
$foundit = $1;
chomp $foundit;
}
## I have found the .csv format to download and extracted that filename in the Fiddler output below
print "Found stuff is '|' $foundit '|'\n";
$foundit =~ s/%/%25/g;
## I've replaced the % with %25
print "NEWFound stuff is '|' $foundit '|'\n";
print "filename=$foundit";
## This is where I get the error page instead of the JSON return
$amazon_parameters = $mech->post("https://zipcodedownload.com/customer/DownloadProdCut",filename=>"$foundit", Content_type=>'application/x-www-form-urlencoded');
print $mech->success();
print Data::Dumper->Dump([$amazon_parameters],[qw(a*)]);
####
POST https://zipcodedownload.com/customer/DownloadProdcut HTTP/1.1
Host: zipcodedownload.com
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1
Accept: */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: https://zipcodedownload.com/Account
Content-Length: 117
Cookie: __utma=229236631.568973291.1315837689.1340122206.1340129864.17; __utmz=229236631.1319476276.4.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=zipcodedownload.com; Nop.customer=452ca35c-69c3-4f7c-8692-9d30fcedd480; NOPCOMMERCE.AUTH=EDE502A471B6DC7B016B392FB36330FA28B3ABD510C53A71BAA359AB0CCB420F47E65A3D7FBF288A4A19FB54552E6B33109B1A84A9C86291093021EA1123D262EADDCD722636959B0D7A6B85E5A2D3078D9AEC778CC46DE831BF625B13DBFA46145167B4054A25C8FCBC7E40803846BE1A7FB36688DF39E4A262B2016C5712DB4C1052DA8E57495AE7EBABC538E2B722159FF8D06F5216AD244AA4541E6B97466D0E605EB00702D48E455CDD318D4BAF17EC1E82F9C2F212BB1A6667ABA0C54FCD5386AC785D9856001F9CFA93DC30EB; __utmb=229236631.2.10.1340129864; __utmc=229236631
Pragma: no-cache
Cache-Control: no-cache
filename=WstR8%252baW3oKaUe69z3dsh%252f2MdaofcaimgKF5jkLsglXb25Hu4oNg8WKsht35ARX0BphaEq%252bN7NHMwomQra8VJg%253d%253d
####
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
Set-Cookie: Nop.customer=452ca35c-69c3-4f7c-8692-9d30fcedd480; expires=Wed, 19-Jun-2013 18:18:03 GMT; path=/
X-Powered-By: ASP.NET
Date: Tue, 19 Jun 2012 18:18:03 GMT
Content-Length: 192
{"Status":true,"Url":"http://zipcodedownload.s3.amazonaws.com/jun2012_z5c6combined_csv.zip?AWSAccessKeyId=############2XFX6WA&Expires=1340129914&Signature=jc7OMAiQ9CBc4CEsM%2FvmLEQF%2B2Q%3D"}