1

我有一个程序,它使用 HTML::TagParser 和图书的条形码为一本书引入一个页面,抓取一定的跨度,为不同的页面重复它,然后将其添加到 TK::MListbox 直到选择导出它。这在 Eclipse 中运行良好。但是,一旦使用 par-packer 制作了 .exe,该程序就无法运行。使用条形码 31412007436751 时的错误是这样的:

Tk::Error: URI::Fetch failed: https://i-share.carli.illinois.edu/uis/cgi-bin/shelflister.cgi?search=s1&bcs=31412007436751&bce=&stpt=1&mode=1 at script/ShelfLister_Lister.pl line 32.
 Carp::croak at C:/strawberry/perl/lib/Carp.pm line 100
 HTML::TagParser::fetch at HTML/TagParser.pm line 261
 HTML::TagParser::new at HTML/TagParser.pm line 239
 main::addBook at script/ShelfLister_Lister.pl line 32
 <Key-Return>
 (command bound to event)

相关的程序代码是这样的:

#!/user/bin/perl
use strict;
use warnings;
use Tk;
use Tk::MListbox;
use LWP::Simple;
use URI::Fetch;
use Encode::Byte;
use HTTP::Response;
use HTML::TagParser;
use Spreadsheet::WriteExcel;

my ($callNumber, $title, $html, $numItems);
my $savetypes = [['Excel Files', '.xls'], ['Comma-Separated Files', '.csv'], ['Text Files', '.txt']];
my $mw = new MainWindow;
$mw->title("Barcode Lister");
$mw->Label(-text=>'Choose Books')->grid(-row=>1, -column=>1, -columnspan=>2, -pady=>10);
my $barcode = $mw->Entry(-width=>50)->grid(-row=>2, -column=>1, -pady=>5, -padx=>[5, 10]);
my $add = $mw->Button(-text=>'Add Record', -command=>\&addBook, -width=>15)->grid(-row=>2, -column=>2, -pady=>5);
my $listFrame = $mw->Frame(-bd=>2, -relief=>"sunken")->grid(-row=>3, -column=>1, -padx=>[5, 10], -pady=>5);
my $list = $listFrame->Scrolled(qw(MListbox -background white -scrollbars oe))->pack(-expand=>1, -fill=>"both");
$list->columnInsert('end', -text=>"Call number", -width=>23);
$list->columnInsert('end', -text=>"Title", -width=>25);
my $delete = $mw->Button(-text=>'Delete Record', -command=>\&removeBook, -width=>15)->grid(-row=>3, -column=>2, -pady=>5);
my $export = $mw->Button(-text=>'Export List', -command=>\&exportList, -width=>15)->grid(-row=>4, -column=>1, -columnspan=>2, -pady=>5);
$barcode->bind('<Return>'=>\&addBook);
$barcode->focus;

MainLoop;

sub addBook{
    $html = HTML::TagParser->new('https://i-share.carli.illinois.edu/uis/cgi-bin/shelflister.cgi?search=s1&bcs=' . $barcode->get() . '&bce=&stpt=1&mode=1');
    $title = $html->getElementsByClassName('listLine');
    if (ref $title){
        $html = HTML::TagParser->new('https://i-share.carli.illinois.edu/uis/cgi-bin/shelflister.cgi?search=s1&bcs=' . $barcode->get() . '&bce=&stpt=1&mode=2');
        $list->insert("end", [$title->innerText(), $html->getElementsByClassName('listLine')->innerText()]);
        $barcode->delete(0, 'end');
    }
    else{
        $mw->messageBox(-title=>'Error', -message=>"Barcode not found.", -type=>'Ok', -icon=>'error', -default=>'ok');
    }
}

任何人都对我如何让它作为.exe工作有任何想法?

4

1 回答 1

1

可能URI::Fetch->errstr会提供有关失败的更多信息。尝试修补 HTML::TagParser (请参阅https://rt.cpan.org/Ticket/Display.html?id=86698)或者可以将与 HTML::TagParser 相关的代码行包装成一个eval { }并调用errstr在错误中发挥自己的作用。

于 2013-07-04T10:05:28.803 回答