我在 stackoverflow.com 上阅读了您大约 5 个月前提出的一个问题,更确切地说是: 使用 WWW::Mechanize 在亚马逊网站上导航表单
我正在创建一个进入站点并输入我的凭据的脚本,以最终保存站点源代码,以便我可以解析信息。
我有一个问题,我的脚本在用作 .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();