Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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::Mechanize->new(autocheck => 1);
$m->get($url);
$m->form_number(2);
$m->click();
my $response = $m->res();
print $m->response->headers->as_string;

It submits the download button on the page, but I'm not sure how to download the file which is sent back after the POST.

I'm wanting a way to download this with wget if possible. I was thinking that their may be a secret url passed or something? Or will I have to download it with LWP directly from the response stream?

So how do I download the file that is in that header?

Thanks,

Cody Goodman

like image 294
codygman Avatar asked Oct 14 '22 12:10

codygman


1 Answers

After submitting the form, you can use:

$mech->save_content( $filename )

Dumps the contents of $mech->content into $filename. $filename will be overwritten. Dies if there are any errors.

If the content type does not begin with "text/", then the content is saved in binary mode.

Source: http://metacpan.org/pod/WWW::Mechanize

like image 157
Pavel Avatar answered Oct 31 '22 17:10

Pavel