How do I download a file with WWW::Mechanize after it submits a form?

后端 未结 3 904
自闭症患者
自闭症患者 2021-01-19 04:21

I have the code:

#!/usr/bin/perl
use strict;
use WWW::Mechanize;

my $url = \'http://divxsubtitles.net/page_subtitleinformation.php?ID=111292\';
my $m = WWW:         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-19 05:20

    Well the thing that threw me off the most was the "mechanize->form_number" subroutine starts at 1 whereas typical programs start their index at 0. If anyone wants to know how to download response headers, or download header attachments, this is the way to do it.

    Now here's the full code to do what I wanted.

    #!/usr/bin/perl
    use strict;
    use WWW::Mechanize;
    
    my $url = 'http://divxsubtitles.net/page_subtitleinformation.php?ID=111292';
    my $m = WWW::Mechanize->new(autocheck => 1);
    $m->get($url);
    $m->form_number(2);
    $m->click();
    my $response = $m->res();
    my $filename = $response->filename;
    
    if (! open ( FOUT, ">$filename" ) ) {
        die("Could not create file: $!" );
    }
    print( FOUT $m->response->content() );
    close( FOUT );
    

提交回复
热议问题