作者adu (^_^)
看板Perl
标题[问题] 网页上的全域比对
时间Mon Nov 2 14:50:53 2009
在文件当中全域比对使用/g就可以,不过我同样的方式套用到网页上没有产生功能
不知道是不是Mechanize有另外的改法?
是延伸之前的问题,把要查询的部分丢上网路,然後抓取部分结果下来
当我要比对的部分超过一个时,就只比对到第一个就输出了
不知道有没有办法将整个网页都扫过?
实际的例子:
於PDBsum中输入2v69(id)
http://www.ebi.ac.uk/thornton-srv/databases/cgi-bin/pdbsum/GetPage.pl
抓取Uniprot後面的数字
此处的input为
"2v69"
理想的output为
"2v69, P00877, P00873"
不过现在的code只能抓到
"2v69, P00877" 後面的会漏掉。
目前的script:
#!/usr/bin/perl
use WWW::Mechanize;
my $file = "input.txt";
my $ofile = ">output.txt";
my $checkURL = "
http://www.ebi.ac.uk/pdbsum/";
open FILE, $file or die "File open error!!";
open FILE2, $ofile or die "File open error!!";
my $mech = WWW::Mechanize -> new();
my $result;
while(<FILE>){
chomp;
$_=~ s/ //g;
$mech -> get($checkURL);
$mech -> submit_form(
form_number => 1,
fields => {
template => "main.html",
EBI => "TRUE",
pdbcode => $_,
},
);
if($mech->content=~/http:\/\/www.uniprot.org\/uniprot\/(\D\S\S\S\S\S)/msg)
{ print FILE2 "$_ , $1\n"; }
else
{print FILE2 "$_ \n"; }
}
close FILE;
close FILE2;
~~~~
主要是用最後面一段的if($mech->content=~比对原始码
--
再次感谢曾协助过我的版大m(__ __)m
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.114.88.228
1F:推 freshroger:@arr = ( $mech->content = ...... ); 11/02 23:10
2F:→ freshroger:for $entry (@arr) { $output .= ",$entry";} 11/02 23:10
3F:→ freshroger:print FILE2 "$output\n"; 11/02 23:10
4F:→ freshroger:记得 前面加上 my $output; $output .= $_; 11/02 23:11
5F:→ freshroger:如果你要取少数的data,这样ok,多的话建议直接下载dat档 11/02 23:14
6F:→ freshroger:再一次parse :) 11/02 23:14
了解!
谢谢板大:D
补上一个用while做出来的:
if($mech->content=~/(http:\/\/www.uniprot.org\/uniprot\/\D\d\d\d\d\d)/ms)
{ my $line=$mech->content;
print FILE2 "$_ , ";
while ( $line =~
s/http:\/\/www.uniprot.org\/uniprot\/(\D\d\d\d\d\d)//ms) {
print FILE2 "$1 ";
}
print FILE2 ",\n";
}
else
{print FILE2 "$_ \n"; }
}
很硬来就是..XD
※ 编辑: adu 来自: 140.114.88.228 (11/03 09:37)