繁体   English   中英

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

[英]Get url with Perl module 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 ,我想转到以下URL http://revigo.irb.hr/toR.jsp?table=1并下载它给我的文件。 即使如何阅读cpan手册,也没有任何提示。

我会改用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

未经测试!

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM