Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

www::mechanize executable

by fixon (Initiate)
on Oct 18, 2012 at 05:51 UTC ( #999678=perlquestion: print w/ replies, xml ) Need Help??
fixon has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks! I created a short script that reads an https page enters the credentials, loads the sourcecode and parses it and finally stores all that is needed in a excel file. When I run it it works perfect, when I run it through windows terminal > perl myscript.pl it also works! i.e creates my excel file.

Problem is when I compress it to a executable, e.g. into a myscript.exe with perl2exe or with pp (perl packager), it does not execute, i.e does not create the excel file. I am out of ideas, but I strongly believe it is related to the www::mechanize library. Do any of you have some tips of what the problem might be?

Comment on www::mechanize executable
Re: www::mechanize executable
by Anonymous Monk on Oct 18, 2012 at 06:15 UTC

    but I strongly believe it is related to the www::mechanize library

    I can tell you that it is not

    Whatever the issue is, relative path.... it is a problem with your code and/or the way you packed your program

Re: www::mechanize executable
by Anonymous Monk on Oct 18, 2012 at 07:05 UTC

    Hi fixon,
    it does not execute, i.e does not create the excel file

    How are you using pp(PAR Packager) to make your executable? Using pp like so works for me:

    pp -o perlscript.exe perlscript.pl

      I did exactly that for the pp to create the .exe package

      Here is my code, please take a quick look if you see anything that might be causing the problem when creating the .exe. Thank you very much

      use strict; use Spreadsheet::WriteExcel; use WWW::Mechanize; # 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://anyURLwithCredentials.com' ); # Get the login form. You might need to change the number. $bot->form_number(3); # Enter the login credentials. $bot->field( username => 'username' ); $bot->field( password => 'password' ); $response = $bot->click(); my $outfile = "out.txt"; open(OUTFILE, ">$outfile"); print OUTFILE $response->decoded_content; close(OUTFILE); open(FILE,$outfile); my @releasesAU; my @releasesAU3G; while (<FILE>) { chomp; my $lineDATA = $_; if(index($lineDATA, "H") != -1){ if( $lineDATA =~ /">([_+\w]*)<\/a>/){ print $1, "\n"; push(@releasesAU3G,$1); } } if(index($lineDATA, "H+") != -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 H"); $worksheet->write($row, $col+1, "Releases H+"); $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();

        Have you inspected whether LWP::Protocol::https (and other dynamically loaded prerequisites of your script) are included in the generated executable?

Re: www::mechanize executable
by fixon (Initiate) on Oct 18, 2012 at 17:14 UTC

    I have tried adding what you suggested use LWP::Protocol::https to my code, but nothing has changed How can I verify allthe automatically generated dependencies for my code? Maybe the problem is only that... thank you

Re: www::mechanize executable
by Anonymous Monk on Oct 18, 2012 at 22:45 UTC

    Hello again monks!

    I debugged as much as I could and found that the problem is my website type I believe. Because if I use www.google.com as my URL, my executable takes the information needed and saves it in the .txt file

    Therefore do any of you have an idea why the website type makes a difference when my script is compressed to an .exe? (if i compress the script with the url=www.google.com, it works fine<\p>

      Have you checked with URLs that need HTTPS?

        Hello Corion, Yes I have noticed that the problem is only related to sites that have authentification. So for example hotmail.com (https://hotmail.com) will not work either. What I can't understand is that the script works fine whichever site I choose to parse.

        But when I package the script it only works with none secured websites. For example www.google.com will get parsed by the packaged script (.exe) I debugged and the process stops exactly when I call the https site i.e. at line:

        # Connect to the login page my $response = $bot->get( 'https://anyURLwithCredentials.com' );

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://999678]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-09-16 21:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (49 votes), past polls