I read a question you asked about 5months ago on stackoverflow.com more precisly here it is: Using WWW::Mechanize to navigate forms on Amazon site
I am creating a script that enters a site and enters my credentials, to finally save the sites source code so I can parse the information.
I have a problem, my script works totally fine when used as a .pl script or on eclipse. But once I package it into a .exe it does not function. I noticed that it is related to my site type, more precisely any sites needing credentials i cannot package them into an functioning executable. Would you by any chance have an idea what the problem might be?
thank you very much!
here is my code:
#!/usr/local/bin/perl
use Spreadsheet::WriteExcel;
use WWW::Mechanize;
use Win32::Registry;
use LWP::Protocol::https;
use LWP;
use HTTP::Cookies;
use HTTP::Server::Simple;
use Net::HTTP;
use Pod::Usage;
use HTTP::Status;
use HTML::Form;
use Bundle::WWW::Mechanize::Shell;
# kills cmd prompt when .exe used on win32
BEGIN {
if ($^O eq 'MSWin32') {
require Win32::Console;
Win32::Console::Free( );
}
}
# Create a new instance of Mechanize
my $bot = WWW::Mechanize->new();
$bot->agent_alias( 'Windows Mozilla' );
# Connect to the login page
my $response = $bot->get('https://siteWithCredentials.com/' );
die "GET failed url" unless $response->is_success;
# Get the login form. You might need to change the number.
$bot->form_number(3);
# Enter the login credentials.
$bot->field( username => 'a username' );
$bot->field( password => 'a password' );
$response = $bot->click();
$bot->get('http://sitewithCredentials/directoryIamParsing.html' );
my $content = $bot->content();
my $outfile = "out.txt";
open(OUTFILE, ">$outfile");
print OUTFILE $content;
close(OUTFILE);
open(FILE,$outfile);
my @releasesAU;
my @releasesAU3G;
while (<FILE>) {
chomp;
my $lineDATA = $_;
if(index($lineDATA, "HN+_US_AU3G") != -1){
if( $lineDATA =~ /">([_+\w]*)<\/a>/){
print $1, "\n";
push(@releasesAU3G,$1);
}
}
if(index($lineDATA, "HN+R_US_AU") != -1){
if( $lineDATA =~ /">([_+\w]*)<\/a>/){
print $1, "\n";
push(@releasesAU,$1);
}
}
}
close(FILE);
my $row = 0;
my $col=0;
my $workbook = Spreadsheet::WriteExcel->new("test.xls");
my $worksheet = $workbook->add_worksheet();
$worksheet->write($row, $col, "Releases HN+R_US_AU3G");
$worksheet->write($row, $col+1, "Releases HN+R_US_AU3G");
$row=2;
foreach my $SOP (@releasesAU){
$worksheet->write($row, $col, $SOP);
$row = $row+1;
}
$row =2;
foreach my $SOP (@releasesAU3G){
$worksheet->write($row, $col+1, $SOP);
$row = $row+1;
}
$workbook->close();