使用Perl模块WWW :: Mechanize获取URL

时间:2014-12-15 15:24:28

标签: perl cpan www-mechanize

我找到了以下代码:

use WWW::Mechanize;
use WWW::Mechanize::FormFiller;
use URI::URL;

my @go_terms=qw/GO:0006612 GO:0045862 GO:0048545 GO:0007568 GO:0046326 GO:0051901  GO:0010524 GO:0006044 GO:0032024/;
my $go_string=join("\n",@go_terms);
my $agent = WWW::Mechanize->new( autocheck => 1 );
my $formfiller = WWW::Mechanize::FormFiller->new();
$agent->env_proxy();

$agent->get('http://revigo.irb.hr/');
$agent->form_number(1) if $agent->forms and scalar @{$agent->forms};
$formfiller->add_filler( 'goList' => Fixed => $go_string);
$formfiller->add_filler( 'cutoff' => Fixed => '0.4' );
$formfiller->add_filler( 'isPValue' => Fixed => 'yes' );
$formfiller->add_filler( 'whatIsBetter' => Fixed => 'higher' );
$formfiller->add_filler( 'goSizes' => Fixed => 0 );
$formfiller->add_filler( 'measure' => Fixed => 'SIMREL' );
$formfiller->fill_form($agent->current_form);

my $request = $agent->click("startRevigo");

我要做的是,点击startRevigo后,我想转到以下网址http://revigo.irb.hr/toR.jsp?table=1并下载它给我的文件。不知道如何做到这一点,甚至阅读cpan手册。

2 个答案:

答案 0 :(得分:0)

我使用LWP::UserAgent代替

require LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;

my $response = $ua->get('http://revigo.irb.hr/toR.jsp?table=1');

if ($response->is_success) {
    print $response->decoded_content;  # I am just printing it but you can save it etc
}
else {
    die $response->status_line;
}

http://search.cpan.org/dist/libwww-perl/lib/LWP/UserAgent.pm

答案 1 :(得分:0)

未经过测试!

use WWW::Mechanize;

my @go_terms=qw/GO:0006612 GO:0045862 GO:0048545 GO:0007568 GO:0046326 GO:0051901  GO:0010524 GO:0006044 GO:0032024/;
my $go_string=join("\n",@go_terms);

my $agent = WWW::Mechanize->new( autocheck => 1 );
$agent->env_proxy();

$agent->get('http://revigo.irb.hr/');
$agent->submit_form(
    with_fields => {

        goList => $go_string,
        cutoff => 0.4
        isPValue => "yes",
        whatIsBetter => "higher",
        goSizes => 0,
        measure => "SIMREL",
    },
);

$agent->get("http://revigo.irb.hr/toR.jsp?table=1");
$agent->save_content("your_file.r");