2012-02-08 49 views
0

有没有人在http://oreilly.com/pub/h/974#code上运行perl脚本?从“Yahoo! Directory Mindshare in Google”运行perl hack

这是一个着名的,用于从Yahoo!获取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 =排序{$网址{$ B} < => $网址{$ A}}键%的网址,”。

我对perl没有任何理解,但这个任务应该是微不足道的。

当然,我错过了一些非常明显的东西,因为这个脚本已经被很多人成功地使用了。

在此先感谢。

回答

1

您是否向脚本提供目录?因为如果你不和这条线在脚本

"/Computers_and_Internet/Data_Formats/XML_ _". 
       "eXtensible_Markup_Language_/RSS/News_Aggregators/" 

不是格式化假象,然后你想刮一个不存在的页面。

+0

嘿,即使运行它作为 “perl mindshare.pl”/娱乐/幽默/拖延/“”没有帮助。 “GoogleSearch.wsdl”存在于同一目录中。还有什么我需要做的? – instanceOfObject 2012-02-08 12:34:35

+0

我甚至尝试过不使用“GoogleAPIKey”并修改函数定义来收回较少的参数。 – instanceOfObject 2012-02-08 12:43:14

+0

我没有Googleapi密钥或时间测试脚本,但是:以perl -d mindshare.pl运行脚本,它会将您放入perl调试器中。单步执行程序'p'和'x'将帮助您查看变量中的内容('l'将列出您的位置)。从你说的话来看,关联数组%URL没有被填充。 – 2012-02-08 14:16:53