我必须在多个网页上填写表格。我正在尝试获取数据,将 html 解析为文本,并将其存储在一个文件中。每个网络表单都有不同的字段需要填写;这是其中之一的代码。我还有三个。建议表示赞赏 - 谢谢!
use strict;
use warnings;
my $timeout=40;
use WWW::Mechanize;
use HTML::TreeBuilder;
use HTML::FormatText;
use HTML::Parser;
use autodie qw/ open close /;
use 5.012;
use Win32::IE::Mechanize;
use Time::HiRes 'sleep';
my $m = WWW::Mechanize->new(autocheck => 1);
my $browser = Win32::IE::Mechanize->new(visible => 1);
my $snp = "rs111";
my $content= $browser->get("http://snp-nexus.org/index.html");
my $html = $browser->content;
$browser->form_name ('snpnexus');
$browser->field('batch_text', 'dbsnp rs111');
$browser->tick('ensembl', "ensembl");
$browser->tick('refseq','refseq');
$browser->tick('ucsc','ucsc');
$browser->tick("sift",'sift');
$browser->tick("polyphen",'polyphen');
$browser->tick("chb",'chb');
$browser->tick("chd",'chd');
$browser->tick("tfbs",'tfbs');
$browser->tick("consv",'consv');
$browser->tick("gwas",'gwas');
$browser->tick("indel",'indel');
$browser->tick("mirbase" ,'mirbase');
$browser->tick('gad','gad');
$browser->tick('cnp' , 'cnp' );
$browser->click_button('value', 'RUN');
for (0 .. $timeout*20) {
last if $browser->{agent}->ReadyState >=5;
sleep 0.1;
}
my $html2 = $browser->content;
my $Format =HTML::FormatText->new();
my $TreeBuilder =HTML::TreeBuilder->new();
$TreeBuilder->parse($html2);
my $parsed= $Format->format($TreeBuilder);
print $parsed;