当我尝试以这种方式填写带有文件上传字段的表单时,我收到一个错误,bad file descriptor at ... line ...
在我填写文件输入字段 ( $browser->field('some_file_field',$file) or die "$!";
) 的那一行。我也尝试了普通的斜线,该脚本在 Windows 操作系统下运行。
use strict;
use warnings;
use WWW::Mechanize;
use HTTP::Cookies;
use LWP::Debug qw(+);
my $user = 'user';
my $password = 'password';
my $browser = WWW::Mechanize->new(
stack_depth => 0,
cookie_jar => {},
timeout => 180,
autocheck => 1,
onerror => \&Carp::croak,);
# Login Form
my $response = $browser->get('http://somepage/de/login.php');
if (!$response->is_success) {
die "Login page unreachable: ", $response->status_line, "\n";
}
$browser->field('userid', $user);
$browser->field('passwd', $password);
$response = $browser->click();
if ($response->is_success) {
print "Login Successful!\n";
} else {
die "Login failed: ", $response->status_line, "\n";
}
$response = $browser->get('http://somepage/import.php');
if (!$response->is_success) {
die "Static Data Site unreachable: ", $response->status_line, "\n";
}
my $form = $browser->form_name('importform');
$browser->select('some_select_field','test') or die "$!";
my $file = 'C:\test.txt';
$browser->field('some_file_field',$file) or die "$!";
$response = $browser->submit() or die "$!";
if ($response->is_success) {
print "Import Successful!\n";
} else {
die "Import failed: ", $response->status_line, "\n";
}