我看你問5個月前就stackoverflow.com更多precisly這裏的一個問題是: Using WWW::Mechanize to navigate forms on Amazon site萬維網::機械化perl的,可執行
我創建進入一個網站,並進入我的憑據,到一個腳本最後保存網站源代碼,以便我可以解析信息。
我有一個問題,我的腳本在用作.pl腳本或eclipse時完全正常。但是,一旦我將它打包成.exe文件,它就不起作用。我注意到它與我的網站類型有關,更確切地說,任何需要憑據的網站我都無法將它們打包到正在運行的可執行文件中。 你有沒有想過這個問題可能是什麼?
非常感謝你!
這裏是我的代碼:
#!/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();
謝謝nslntmnx, 我已經採取了: BEGIN { 如果($^o EQ 'MSWin32'){ 需要的Win32 ::控制檯; Win32 :: Console :: Free(); } } 出了代碼,它不會改變任何東西。 調試完成後,我注意到打包到.exe的腳本**對不需要憑據的站點起作用**。只有當html頁面需要認證時,它纔會停在我呼叫的第一行: my $ response = $ bot-> get('https://siteWithCredentials.com/'); 這是否給你任何進一步的想法問題所在。注意:當我運行它作爲腳本它的作品! – user1757842