2

在使用WWW::Mechanize. 该文件已正确上传,但名称已损坏(我仅??????在目标站点上看到)。

代码很简单:

use WWW::Mechanize;
use Encode qw(from_to);

my $config = {

    login         => "login",
    password      => "pass",
    source_folder => "$Bin/source_folder",
};

my $mech = WWW::Mechanize->new( autocheck => 1 );
$mech->agent_alias("Windows IE 6");

$mech->get("http://www.antiplagiat.ru/Cabinet/Cabinet.aspx?folderId=689935");
authorize($mech);

$mech->submit_form(

    form_number => 1,
    fields      => {},
    button =>
'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$FolderControl_StdFolder_0$DocumentsGrid$btnAddItem',
);

find( \&wanted, $config->{source_folder} );

sub wanted {

    return unless -f;

    say $config->{source_folder} . "/" . $_;

    #from_to($_, "CP1251", "UTF8"); doesn't work too :-(

    my $mech = $mech->clone();
    $mech->submit_form(

        form_number => 1,
        fields      => {

            'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$fuDocumentUpload' =>
              $config->{source_folder} . "/" . $_,
        },
        button => 'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$btnCommitUpload',
    );
}

如果我将文件名从 CP1251 编码为 UTF8,则上传不起作用。请帮我找到解决方案。

4

1 回答 1

1

这是我使用的解决方案:

   my $filename = $_;
    from_to( $filename, "CP1251", "UTF8" );

    my $mech = $mech->clone();

    my $form = $mech->form_number(1);
    $mech->field( 'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$fuDocumentUpload',
        $config->{source_folder} . "/" . $_ );
    $form->find_input(
        'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$fuDocumentUpload')->filename($filename);
    $mech->submit_form(

        form_number => 1,
        button => 'ctl00$ctl00$Body$MainWorkSpacePlaceHolder$btnCommitUpload',
    );
于 2012-07-07T00:20:56.570 回答