0

http://oreilly.com/pub/h/974#codeで提供されているperlスクリプトを実行している人はいますか?

これは有名なもので、Yahoo!からURLを取得するために使用されます。ディレクトリと多くの人々がそれをうまく使用しています。

URLを取得しようとしていました。独自のGoogleAPIキーを作成し、コードで置き換えました。それを除けば、私は何も変更しませんでした。

スクリプトはエラーも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について何も理解していませんが、このタスクは簡単なはずです。

確かに、このスクリプトは多くの人にうまく使用されているので、私は非常に明白な何かを見逃しています。

前もって感謝します。

4

1 に答える 1

1

スクリプトにディレクトリを提供していますか?そうでない場合は、スクリプトのこの行

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

はフォーマットのアーティファクトではないため、存在しないページをスクレイプしようとしています。

于 2012-02-08T12:18:33.797 に答える