我无法通过perl-get、bash命令get和wget下载特定页面



我下载页面时遇到问题,

my $url='http://www.ncbi.nlm.nih.gov/nuccore?linkname=pcassay_nucleotide&from_aid=504934,1806,1805,1674';

我可以用浏览器浏览以下内容,但当我在perl或linuxshell中运行bash命令时,

GET $url >OUTPUT1;  # Even it does not write anything to file "OUPUT1"

当我尝试wget时,它下载但不正确,我的意思是--><title>Error - Nucleotide - NCBI</title>。我想要有项目的页面,但它会返回一个没有项目的页面。

my $html = qx{wget --quiet --output-document=OUTPUT1 $url};

**注意:几分钟前我注意到,Mozilla firefox可以使用url,但不能通过谷歌chrome浏览。这很奇怪,可能我的问题也与此有关。知道吗?

来自链接的代码:

my $url='http://www.ncbi.nlm.nih.gov/nuccore?linkname=pcassay_nucleotide&from_aid=504934,1806,1805,1674';

my $html = qx{wget --quiet --output-document=OUTPUT11 $url};
# wget get something, but it does not get items, it gets what I get via google chrome
`GET $url2 >OUTPUT11`; # it does not write anything to file,

好吧,考虑到您的代码,问题几乎可以肯定是插值问题。因为URL中的&将被您生成的shell解释为"后台进程"。

这几乎肯定不是你想要的。为什么不直接使用LWP?

#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
my $url='http://www.ncbi.nlm.nih.gov/nuccore?linkname=pcassay_nucleotide&from_aid=504934,1806,1805,1674';
my $content = get $url;
print $content;
open ( my $output_fh, '>', 'output.html' ) or die $!;
print {$output_fh} $content; 
close ( $output_fh );

最新更新