有没有人运行http://oreilly.com/pub/h/974#code给出的 perl 脚本?
这是一个著名的,用于从 Yahoo! 获取 URL!目录,很多人都成功使用过。
我试图获取 URL。我创建了自己的 Google API 密钥并在代码中替换了它。除此之外,我没有做任何改变。
脚本既不产生任何错误也不产生任何 URL。
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
use HTML::LinkExtor;
use SOAP::Lite;
my $google_key = "your API key goes here";
my $google_wdsl = "GoogleSearch.wsdl";
my $yahoo_dir = shift || "/Computers_and_Internet/Data_Formats/XML_ _".
"eXtensible_Markup_Language_/RSS/News_Aggregators/";
# download the Yahoo! directory.
my $data = get("http://dir.yahoo.com" . $yahoo_dir) or die $!;
# create our Google object.
my $google_search = SOAP::Lite->service("file:$google_wdsl");
my %urls; # where we keep our counts and titles.
# extract all the links and parse 'em.
HTML::LinkExtor->new(\&mindshare)->parse($data);
sub mindshare { # for each link we find...
my ($tag, %attr) = @_;
print "$tag\n";
# continue on only if the tag was a link,
# and the URL matches Yahoo!'s redirectory.
return if $tag ne 'a';
return unless $attr{href} =~ /srd.yahoo/;
return unless $attr{href} =~ /\*http/;
# now get our real URL.
$attr{href} =~ /\*(http.*)/; my $url = $1;
print "hi";
# and process each URL through Google.
my $results = $google_search->doGoogleSearch(
$google_key,"link:$url", 0, 1,
"true", "", "false", "", "", ""
); # wheee, that was easy, guvner.
$urls{$url} = $results->{estimatedTotalResultsCount};
print "1\n";
}
# now sort and display.
my @sorted_urls = sort { $urls{$b} <=> $urls{$a} } keys %urls;
foreach my $url (@sorted_urls) { print "$urls{$url}: $url\n"; }
程序进入循环,并在第一次迭代时出现“my @sorted_urls = sort { $urls{$b} <=> $urls{$a} } keys %urls;”。
我对 perl 没有任何了解,但这项任务应该是微不足道的。
当然,我遗漏了一些非常明显的东西,因为这个脚本已经被许多人成功使用。
提前致谢。