[英]Running perl hack from “Yahoo! Directory Mindshare in Google”
有人运行过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"; }
程序进入循环,并在第一次迭代时出现“我的@sorted_urls = sort {$ urls {$ b} <=> $ urls {$ a}}键%urls;”。
我对perl没有任何了解,但这项任务本来应该是微不足道的。
当然,我缺少一些非常明显的东西,因为该脚本已被许多人成功使用。
提前致谢。
您是否在向脚本提供目录? 因为如果不是,那么脚本中的这一行
"/Computers_and_Internet/Data_Formats/XML_ _".
"eXtensible_Markup_Language_/RSS/News_Aggregators/"
不是格式化文物,则您要尝试抓取不存在的页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.