簡體   English   中英

www :: mechanize perl,可執行

[英]www::mechanize perl, executable

我在5個月前在stackoverflow.com上更仔細地閱讀了您問的一個問題,它是: 使用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();

意見建議:
1)是否在“ require”行中報告了錯誤?
由於您知道要編譯為Windows exe,因此測試MSWin32是多余的。 刪除測試,然后將“ require”轉換為“ use”語句,以查看是否有幫助。
2)請使用任何錯誤消息更新您的問題。
3)PERL 101-使用嚴格的警告語。
4)添加代碼以檢查可能失敗的語句的結果,例如打開,打印和關閉。
5)是否真的需要編寫文件內容? 將<FILE>替換為$ content上的拆分
6)不建議使用類型團(例如FILE,OUTFILE)。 嘗試打包FileHandle。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM