##
##
#!/usr/local/bin/perl
use strict; use warnings;
use LWP;
use Crypt::SSLeay;
use HTTP::Cookies;
use WWW::Mechanize;
use HTML::Parser;
use HTTP::Request;
use HTML::TableExtract;
use HTML::Query;
use HTML::Form;
use File::Path qw{mkpath};
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
my $HOME = $ENV{HOME} . '/tmp';
mkpath $HOME unless -d $HOME;
# create a cookie jar on disk
my $cookies = HTTP::Cookies->new(
file => $HOME.'/cookies.txt',
autosave => 1,
);
# create an user-agent and assign the cookie jar to it
my $http = LWP::UserAgent->new();
$http->cookie_jar($cookies);
# Get Main page
my $browser = LWP::UserAgent->new;
my $response = $browser->post(
'https://prism.telcordia.com/tnsc/index.cfm', [
'LOGIN' => 'GDD',]
);
# check if log in succeeded
if($response->is_success){
print "- Main page passed"."\n";
print "- try to log on now"."\n";
}
# try to log in
my $login = $http->post(
'https://prism.telcordia.com/tnsc/login.cfm', [
userName => 'XXXX',
password => 'XXXX',
prod => 'GDD',
LOGIN => 'action',]
);
# check if log in succeeded
if($login->is_success){
print "- logged in successfully"."\n";
print "- requesting file, might take a while"."\n";
}
# Get to download page
my $url = 'https://prism.telcordia.com/tnsc/confirm_login.cfm';
$browser = LWP::UserAgent->new;
$response = $browser->get($url);
# check if log in succeeded
if($response->is_success){
print "- Download page passed"."\n";
print "- try to download now"."\n";
}
# make request to download the file
# my $url = 'https://prism.telcordia.com/tnsc/confirm_login.cfm';
#my $file_req = HTTP::Request->new('GET', $url);
#my $get_file = $http->request( $file_req );
my $te = HTML::TableExtract->new( headers => [qw(File Size Date)] );
$te->parse($url);
# Examine all matching tables
foreach my $ts ($te->tables) {
print "Table (", join(',', $ts->coords), "):\n";
foreach my $row ($ts->rows) {
print join(',', @$row), "\n";
}
}
# check request status
if($get_file->is_success){
print "--> downloaded $url, saving it to file";
# save the file content to disk
open my $fh, '>', $HOME.'/*.zip'
or die "ERROR: $!n";
print $fh $get_file->decoded_content;
close $fh;
print "saved file"."\n";
print "------------"."\n";
print "filename: ".$get_file->filename."\n";
print "size: ".(-s $HOME.'/*.zip')."\n";
}
else {
die "ERROR: download of $url failed: " . $get_file->status_line . "\n";
}
}
else {
die "ERROR: login failed: " .$login->status_line . "\n";
}