在提交表单后,如何使用WWW :: Mechanize下载文件? [英] How do I download a file with WWW::Mechanize after it submits a form?

查看:188
本文介绍了在提交表单后,如何使用WWW :: Mechanize下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码:

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

我的$ 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;

它提交页面上的下载按钮,但我不知道如何下载文件在POST后发送回来。



如果可能,我想要一个下载wget的方法。我在想,他们可能是一个秘密的URL通过或什么?或者我必须直接从响应流下载LWP?



那么如何下载该标题中的文件?

$ b $谢谢,



Cody Goodman

解决方案

嗯,最令我失望的是机械化 - > form_number子程序从1开始,而典型的程序将其索引开始为0.如果有人想知道如何下载响应标头,或下载头文件附件,这是这样做。



现在这里是完成我想要的代码。 >

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

我的$ 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();
我的$ filename = $ response-> filename;

如果(!open(FOUT,> $ filename)){
die(无法创建文件:$!
}
print(FOUT $ m-> response-> content());
close(FOUT);


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

解决方案

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 );

这篇关于在提交表单后,如何使用WWW :: Mechanize下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆